This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[GCC][PATCH] Enable underflow check in canonicalize_comparison. (PR86995)


Hi.

r263591 introduced the following regressions on multiple platforms:
+FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O0  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O2 -flto  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O2 -flto -flto-partition=none  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O0  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O2  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O2 -flto  execution test
+FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O2 -flto -flto-partition=none  execution test

The cause for this was that in canonicalize_comparison wi::add was used to add a negative number.  This meant
that in case of underflow the flag would not have been set.  The solution is to use wi::sub if the immediate
needs to be decremented.

The patch fixes the mentioned regressions.
Bootstrapped and regtested on aarch64-none-linux-gnu and x86_64-pc-linux-gnu.

Thanks,
Vlad

---

diff --git a/gcc/expmed.c b/gcc/expmed.c
index be9f0ec9011..84f58f540ab 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -6235,7 +6235,13 @@ canonicalize_comparison (machine_mode mode, enum rtx_code *code, rtx *imm)
      wrapping around in the case of unsigned values.  If any occur
      cancel the optimization.  */
   wi::overflow_type overflow = wi::OVF_NONE;
-  wide_int imm_modif = wi::add (imm_val, to_add, sgn, &overflow);
+  wide_int imm_modif;
+
+  if (to_add == 1)
+    imm_modif = wi::add (imm_val, 1, sgn, &overflow);
+  else
+    imm_modif = wi::sub (imm_val, 1, sgn, &overflow);
+
   if (overflow)
     return;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]