aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-01-24 15:26:46 +0100
committerRichard Biener <rguenther@suse.de>2022-02-04 12:54:35 +0100
commit24c72fb0eedfe7c67f9b15aa31b474a999cc4723 (patch)
treee37bf8a72449e7e5cc59a280b791c037f681d5f9 /gcc
parent38948b77dbc16f4c6cf6cff8661bab699b306f03 (diff)
downloadgcc-24c72fb0eedfe7c67f9b15aa31b474a999cc4723.zip
gcc-24c72fb0eedfe7c67f9b15aa31b474a999cc4723.tar.gz
gcc-24c72fb0eedfe7c67f9b15aa31b474a999cc4723.tar.bz2
Adjust LSHIFT_EXPR handling of multiple_of_p
This removes the odd check of size_type_node when handling left-shifts as multiplications of 1 << N and instead uses the type as specified. It also moves left-shift handling next to multiplications where it semantically belongs. 2022-01-24 Richard Biener <rguenther@suse.de> * fold-const.cc (multiple_of_p): Re-write and move LSHIFT_EXPR handling.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fold-const.cc33
1 files changed, 16 insertions, 17 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 8fc01cd..12732d3 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -14079,7 +14079,7 @@ int
multiple_of_p (tree type, const_tree top, const_tree bottom)
{
gimple *stmt;
- tree t1, op1, op2;
+ tree op1, op2;
if (operand_equal_p (top, bottom, 0))
return 1;
@@ -14125,6 +14125,21 @@ multiple_of_p (tree type, const_tree top, const_tree bottom)
return (multiple_of_p (type, TREE_OPERAND (top, 1), bottom)
|| multiple_of_p (type, TREE_OPERAND (top, 0), bottom));
+ case LSHIFT_EXPR:
+ /* Handle X << CST as X * (1 << CST) and only process the constant. */
+ if (TREE_CODE (TREE_OPERAND (top, 1)) == INTEGER_CST)
+ {
+ op1 = TREE_OPERAND (top, 1);
+ if (wi::to_widest (op1) < TYPE_PRECISION (type))
+ {
+ wide_int mul_op
+ = wi::one (TYPE_PRECISION (type)) << wi::to_wide (op1);
+ return multiple_of_p (type,
+ wide_int_to_tree (type, mul_op), bottom);
+ }
+ }
+ return 0;
+
case MINUS_EXPR:
/* It is impossible to prove if op0 - op1 is multiple of bottom
precisely, so be conservative here checking if both op0 and op1
@@ -14144,22 +14159,6 @@ multiple_of_p (tree type, const_tree top, const_tree bottom)
return (multiple_of_p (type, op1, bottom)
&& multiple_of_p (type, TREE_OPERAND (top, 0), bottom));
- case LSHIFT_EXPR:
- if (TREE_CODE (TREE_OPERAND (top, 1)) == INTEGER_CST)
- {
- op1 = TREE_OPERAND (top, 1);
- /* const_binop may not detect overflow correctly,
- so check for it explicitly here. */
- if (wi::gtu_p (TYPE_PRECISION (TREE_TYPE (size_one_node)),
- wi::to_wide (op1))
- && (t1 = fold_convert (type,
- const_binop (LSHIFT_EXPR, size_one_node,
- op1))) != 0
- && !TREE_OVERFLOW (t1))
- return multiple_of_p (type, t1, bottom);
- }
- return 0;
-
CASE_CONVERT:
/* Can't handle conversions from non-integral or wider integral type. */
if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (top, 0))) != INTEGER_TYPE)