aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2008-03-12 15:33:45 +0000
committerPaolo Bonzini <bonzini@gcc.gnu.org>2008-03-12 15:33:45 +0000
commitc83bd37c9d8859d4e8dc6d1f021c6e8b8ffabb99 (patch)
treec1959cceb74dfe8a50fb7fa66a39bd956922bdbb /gcc/fold-const.c
parent70fef63aef8a841f20cfa08c88da9ca871a3c8f3 (diff)
downloadgcc-c83bd37c9d8859d4e8dc6d1f021c6e8b8ffabb99.zip
gcc-c83bd37c9d8859d4e8dc6d1f021c6e8b8ffabb99.tar.gz
gcc-c83bd37c9d8859d4e8dc6d1f021c6e8b8ffabb99.tar.bz2
re PR rtl-optimization/34522 (inefficient code for long long multiply when only low bits are needed)
2008-03-12 Paolo Bonzini <bonzini@gnu.org> PR tree-opt/35422 * fold-const.c (fold_unary) <NOP_EXPR>: Distribute a narrowing conversion to the operands of a multiplication. testsuite: 2008-03-12 Paolo Bonzini <bonzini@gnu.org> PR tree-opt/35422 * gcc.dg/vect/slp-7.c: Change target keywords required for vectorizing third loop. * gcc.target/i386/pr35422.c: New. From-SVN: r133144
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 4774661..7cf132b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7926,6 +7926,26 @@ fold_unary (enum tree_code code, tree type, tree op0)
return fold_build1 (BIT_NOT_EXPR, type, fold_convert (type, tem));
}
+ /* Convert (T1)(X * Y) into (T1)X * (T1)Y if T1 is narrower than the
+ type of X and Y (integer types only). */
+ if (INTEGRAL_TYPE_P (type)
+ && TREE_CODE (op0) == MULT_EXPR
+ && INTEGRAL_TYPE_P (TREE_TYPE (op0))
+ && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (op0)))
+ {
+ /* Be careful not to introduce new overflows. */
+ tree mult_type;
+ if (TYPE_OVERFLOW_WRAPS (type))
+ mult_type = type;
+ else
+ mult_type = unsigned_type_for (type);
+
+ tem = fold_build2 (MULT_EXPR, mult_type,
+ fold_convert (mult_type, TREE_OPERAND (op0, 0)),
+ fold_convert (mult_type, TREE_OPERAND (op0, 1)));
+ return fold_convert (type, tem);
+ }
+
tem = fold_convert_const (code, type, op0);
return tem ? tem : NULL_TREE;