aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-07-27 13:08:32 +0200
committerRichard Biener <rguenther@suse.de>2023-07-27 15:55:18 +0200
commitd1c072a1c3411a6fe29900750b38210af8451eeb (patch)
tree1be2c459b42d23ba8214bcaae402ffe2ecc3ccc7 /gcc
parenta426b91b27e28985f47d16827a532fbc28c09bd7 (diff)
downloadgcc-d1c072a1c3411a6fe29900750b38210af8451eeb.zip
gcc-d1c072a1c3411a6fe29900750b38210af8451eeb.tar.gz
gcc-d1c072a1c3411a6fe29900750b38210af8451eeb.tar.bz2
tree-optimization/91838 - fix FAIL of g++.dg/opt/pr91838.C
The following fixes the lack of simplification of a vector shift by an out-of-bounds shift value. For scalars this is done both by CCP and VRP but vectors are not handled there. This results in PR91838 differences in outcome dependent on whether a vector shift ISA is available and thus vector lowering does or does not expose scalar shifts here. The following adds a match.pd pattern to catch uniform out-of-bound shifts, simplifying them to zero when not sanitizing shift amounts. PR tree-optimization/91838 * gimple-match-head.cc: Include attribs.h and asan.h. * generic-match-head.cc: Likewise. * match.pd (([rl]shift @0 out-of-bounds) -> zero): New pattern.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/generic-match-head.cc2
-rw-r--r--gcc/gimple-match-head.cc2
-rw-r--r--gcc/match.pd10
3 files changed, 14 insertions, 0 deletions
diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc
index b4b5bc8..a71c072 100644
--- a/gcc/generic-match-head.cc
+++ b/gcc/generic-match-head.cc
@@ -41,6 +41,8 @@ along with GCC; see the file COPYING3. If not see
#include "tree-eh.h"
#include "langhooks.h"
#include "tree-pass.h"
+#include "attribs.h"
+#include "asan.h"
/* Routine to determine if the types T1 and T2 are effectively
the same for GENERIC. If T1 or T2 is not a type, the test
diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
index d795066..5d6d26d 100644
--- a/gcc/gimple-match-head.cc
+++ b/gcc/gimple-match-head.cc
@@ -47,6 +47,8 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "gimple-range.h"
#include "langhooks.h"
+#include "attribs.h"
+#include "asan.h"
tree do_valueize (tree, tree (*)(tree), bool &);
tree do_valueize (tree (*)(tree), tree);
diff --git a/gcc/match.pd b/gcc/match.pd
index ab7622b..ee6cef6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1059,6 +1059,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& tree_nop_conversion_p (type, TREE_TYPE (@1)))
(lshift @0 @2)))
+/* Shifts by precision or greater result in zero. */
+(for shift (lshift rshift)
+ (simplify
+ (shift @0 uniform_integer_cst_p@1)
+ (if ((GIMPLE || !sanitize_flags_p (SANITIZE_SHIFT_EXPONENT))
+ /* Use a signed compare to leave negative shift counts alone. */
+ && wi::ges_p (wi::to_wide (uniform_integer_cst_p (@1)),
+ element_precision (type)))
+ { build_zero_cst (type); })))
+
/* Shifts by constants distribute over several binary operations,
hence (X << C) + (Y << C) can be simplified to (X + Y) << C. */
(for op (plus minus)