* [PATCH] Fix runtime error for nonlinear iv vectorization(step_mult).
@ 2024-03-21 8:32 liuhongt
2024-03-21 9:18 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: liuhongt @ 2024-03-21 8:32 UTC (permalink / raw)
To: gcc-patches; +Cc: crazylht, hjl.tools
wi::from_mpz doesn't take a sign argument, we want it to be wrapped
instead of saturation, so pass utype and true to it, and it fixes the
bug.
Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk and backport to gcc13?
gcc/ChangeLog:
PR tree-optimization/114396
* tree-vect-loop.cc (vect_peel_nonlinear_iv_init): Pass utype
and true to wi::from_mpz.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr114396.c: New test.
---
gcc/testsuite/gcc.target/i386/pr114396.c | 105 +++++++++++++++++++++++
gcc/tree-vect-loop.cc | 2 +-
2 files changed, 106 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr114396.c
diff --git a/gcc/testsuite/gcc.target/i386/pr114396.c b/gcc/testsuite/gcc.target/i386/pr114396.c
new file mode 100644
index 00000000000..4c4015f871f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr114396.c
@@ -0,0 +1,105 @@
+/* { dg-do run } */
+/* { dg-options "-O1 -fwrapv -fno-vect-cost-model" } */
+
+short a = 0xF;
+short b[16];
+unsigned short ua = 0xF;
+unsigned short ub[16];
+
+short
+__attribute__((noipa))
+foo (short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ b[e] = a *= 5;
+ return a;
+}
+
+short
+__attribute__((noipa))
+foo1 (short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ b[e] = a *= -5;
+ return a;
+}
+
+unsigned short
+__attribute__((noipa))
+foou (unsigned short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ ub[e] = a *= -5;
+ return a;
+}
+
+unsigned short
+__attribute__((noipa))
+foou1 (unsigned short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ ub[e] = a *= 5;
+ return a;
+}
+
+short
+__attribute__((noipa,optimize("O3")))
+foo_o3 (short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ b[e] = a *= 5;
+ return a;
+}
+
+short
+__attribute__((noipa,optimize("O3")))
+foo1_o3 (short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ b[e] = a *= -5;
+ return a;
+}
+
+unsigned short
+__attribute__((noipa,optimize("O3")))
+foou_o3 (unsigned short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ ub[e] = a *= -5;
+ return a;
+}
+
+unsigned short
+__attribute__((noipa,optimize("O3")))
+foou1_o3 (unsigned short a)
+{
+ for (int e = 0; e < 9; e += 1)
+ ub[e] = a *= 5;
+ return a;
+}
+
+int main() {
+ unsigned short uexp, ures;
+ short exp, res;
+ exp = foo (a);
+ res = foo_o3 (a);
+ if (exp != res)
+ __builtin_abort ();
+
+ exp = foo1 (a);
+ res = foo1_o3 (a);
+ if (uexp != ures)
+ __builtin_abort ();
+
+ uexp = foou (a);
+ ures = foou_o3 (a);
+ if (uexp != ures)
+ __builtin_abort ();
+
+ uexp = foou1 (a);
+ ures = foou1_o3 (a);
+ if (uexp != ures)
+ __builtin_abort ();
+
+ return 0;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 4375ebdcb49..2921a9e6aa1 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -9454,7 +9454,7 @@ vect_peel_nonlinear_iv_init (gimple_seq* stmts, tree init_expr,
wi::to_mpz (skipn, exp, UNSIGNED);
mpz_ui_pow_ui (mod, 2, TYPE_PRECISION (type));
mpz_powm (res, base, exp, mod);
- begin = wi::from_mpz (type, res, TYPE_SIGN (type));
+ begin = wi::from_mpz (utype, res, true);
tree mult_expr = wide_int_to_tree (utype, begin);
init_expr = gimple_build (stmts, MULT_EXPR, utype,
init_expr, mult_expr);
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix runtime error for nonlinear iv vectorization(step_mult).
2024-03-21 8:32 [PATCH] Fix runtime error for nonlinear iv vectorization(step_mult) liuhongt
@ 2024-03-21 9:18 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-03-21 9:18 UTC (permalink / raw)
To: liuhongt; +Cc: gcc-patches, crazylht, hjl.tools
On Thu, Mar 21, 2024 at 9:35 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> wi::from_mpz doesn't take a sign argument, we want it to be wrapped
> instead of saturation, so pass utype and true to it, and it fixes the
> bug.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk and backport to gcc13?
OK for both.
Thanks,
Richard.
> gcc/ChangeLog:
>
> PR tree-optimization/114396
> * tree-vect-loop.cc (vect_peel_nonlinear_iv_init): Pass utype
> and true to wi::from_mpz.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr114396.c: New test.
> ---
> gcc/testsuite/gcc.target/i386/pr114396.c | 105 +++++++++++++++++++++++
> gcc/tree-vect-loop.cc | 2 +-
> 2 files changed, 106 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr114396.c
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr114396.c b/gcc/testsuite/gcc.target/i386/pr114396.c
> new file mode 100644
> index 00000000000..4c4015f871f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr114396.c
> @@ -0,0 +1,105 @@
> +/* { dg-do run } */
> +/* { dg-options "-O1 -fwrapv -fno-vect-cost-model" } */
> +
> +short a = 0xF;
> +short b[16];
> +unsigned short ua = 0xF;
> +unsigned short ub[16];
> +
> +short
> +__attribute__((noipa))
> +foo (short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + b[e] = a *= 5;
> + return a;
> +}
> +
> +short
> +__attribute__((noipa))
> +foo1 (short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + b[e] = a *= -5;
> + return a;
> +}
> +
> +unsigned short
> +__attribute__((noipa))
> +foou (unsigned short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + ub[e] = a *= -5;
> + return a;
> +}
> +
> +unsigned short
> +__attribute__((noipa))
> +foou1 (unsigned short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + ub[e] = a *= 5;
> + return a;
> +}
> +
> +short
> +__attribute__((noipa,optimize("O3")))
> +foo_o3 (short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + b[e] = a *= 5;
> + return a;
> +}
> +
> +short
> +__attribute__((noipa,optimize("O3")))
> +foo1_o3 (short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + b[e] = a *= -5;
> + return a;
> +}
> +
> +unsigned short
> +__attribute__((noipa,optimize("O3")))
> +foou_o3 (unsigned short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + ub[e] = a *= -5;
> + return a;
> +}
> +
> +unsigned short
> +__attribute__((noipa,optimize("O3")))
> +foou1_o3 (unsigned short a)
> +{
> + for (int e = 0; e < 9; e += 1)
> + ub[e] = a *= 5;
> + return a;
> +}
> +
> +int main() {
> + unsigned short uexp, ures;
> + short exp, res;
> + exp = foo (a);
> + res = foo_o3 (a);
> + if (exp != res)
> + __builtin_abort ();
> +
> + exp = foo1 (a);
> + res = foo1_o3 (a);
> + if (uexp != ures)
> + __builtin_abort ();
> +
> + uexp = foou (a);
> + ures = foou_o3 (a);
> + if (uexp != ures)
> + __builtin_abort ();
> +
> + uexp = foou1 (a);
> + ures = foou1_o3 (a);
> + if (uexp != ures)
> + __builtin_abort ();
> +
> + return 0;
> +}
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index 4375ebdcb49..2921a9e6aa1 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -9454,7 +9454,7 @@ vect_peel_nonlinear_iv_init (gimple_seq* stmts, tree init_expr,
> wi::to_mpz (skipn, exp, UNSIGNED);
> mpz_ui_pow_ui (mod, 2, TYPE_PRECISION (type));
> mpz_powm (res, base, exp, mod);
> - begin = wi::from_mpz (type, res, TYPE_SIGN (type));
> + begin = wi::from_mpz (utype, res, true);
> tree mult_expr = wide_int_to_tree (utype, begin);
> init_expr = gimple_build (stmts, MULT_EXPR, utype,
> init_expr, mult_expr);
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-21 9:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-21 8:32 [PATCH] Fix runtime error for nonlinear iv vectorization(step_mult) liuhongt
2024-03-21 9:18 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).