From c729951e9c51dabfc3ab7ef864ab2ab8b07b5934 Mon Sep 17 00:00:00 2001 From: Vlad Lazar Date: Thu, 30 Aug 2018 09:30:49 +0000 Subject: [PATCH] Enable underflow check in canonicalize_comparison. (PR86995) gcc/ 2018-08-30 Vlad Lazar PR middle-end/86995 * expmed.c (canonicalize_comparison): Use wi::sub instead of wi::add if to_add is negative. From-SVN: r263973 --- gcc/ChangeLog | 6 ++++++ gcc/expmed.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8865f31a43c..e57a5921559 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-08-30 Vlad Lazar + + PR middle-end/86995 + * expmed.c (canonicalize_comparison): Use wi::sub instead of wi::add + if to_add is negative. + 2018-08-29 Bernd Edlinger PR middle-end/87053 diff --git a/gcc/expmed.c b/gcc/expmed.c index 0922029de80..caf29e88924 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -6239,7 +6239,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; -- 2.30.2