]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Add testcase for missed loop vectorization on x86-64/Windows
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 3 Nov 2025 09:00:22 +0000 (10:00 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 3 Nov 2025 09:03:17 +0000 (10:03 +0100)
It has been fixed by swapping operands during SLP discovery.

gcc/testsuite/
* gnat.dg/vect19.ads, gnat.dg/vect19.adb: New test.
* gnat.dg/vect19_pkg.ads, gnat.dg/vect19_pkg.adb: New helper.

gcc/testsuite/gnat.dg/vect19.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/vect19.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/vect19_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/vect19_pkg.ads [new file with mode: 0644]

diff --git a/gcc/testsuite/gnat.dg/vect19.adb b/gcc/testsuite/gnat.dg/vect19.adb
new file mode 100644 (file)
index 0000000..af6f7e6
--- /dev/null
@@ -0,0 +1,17 @@
+-- { dg-do compile { target i?86-*-* x86_64-*-* } }
+-- { dg-options "-O3 -msse2 -gnatn -fno-tree-slp-vectorize -fdump-tree-vect-details" }
+
+package body Vect19 is
+
+  function NSum (X : Arr; N : Positive) return Arr is
+    Ret : Arr := X;
+  begin
+    for I in 1 .. N loop
+      Ret := Sum (Ret, X);
+    end loop;
+    return Ret;
+  end;
+
+end Vect19;
+
+-- { dg-final { scan-tree-dump "vectorized 1 loops" "vect"  } }
diff --git a/gcc/testsuite/gnat.dg/vect19.ads b/gcc/testsuite/gnat.dg/vect19.ads
new file mode 100644 (file)
index 0000000..475f8d4
--- /dev/null
@@ -0,0 +1,7 @@
+with Vect19_Pkg; use Vect19_Pkg;
+
+package Vect19 is
+
+  function NSum (X : Arr; N : Positive) return Arr;
+
+end Vect19;
diff --git a/gcc/testsuite/gnat.dg/vect19_pkg.adb b/gcc/testsuite/gnat.dg/vect19_pkg.adb
new file mode 100644 (file)
index 0000000..4c3b999
--- /dev/null
@@ -0,0 +1,12 @@
+package body Vect19_Pkg is
+
+  function Sum (X : Arr; Y : Arr) return Arr is
+    Result : Arr;
+  begin
+    for I in X'Range loop
+      Result(I) := X(I) + Y(I);
+    end loop;
+    return Result;
+  end;
+
+end Vect19_Pkg;
diff --git a/gcc/testsuite/gnat.dg/vect19_pkg.ads b/gcc/testsuite/gnat.dg/vect19_pkg.ads
new file mode 100644 (file)
index 0000000..accd8af
--- /dev/null
@@ -0,0 +1,9 @@
+package Vect19_Pkg is
+
+  type Arr is array (1 .. 4) of Float;
+  for Arr'Alignment use 16;
+
+  function Sum (X : Arr; Y : Arr) return Arr;
+  pragma Inline (Sum);
+
+end Vect19_Pkg;