This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] fold-const.c: Fix PR tree-optimization/26622.
- From: Kazu Hirata <kazu at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: roger at eyesopen dot com
- Date: Sun, 21 May 2006 02:37:09 -0700
- Subject: [patch] fold-const.c: Fix PR tree-optimization/26622.
Hi,
Attached is a patch to fix PR tree-optimization/26622.
If you compile the attached testcase on i686, we get an unrecognizable
insn:
(set (reg:QI 119)
(const_int 128 [0x80]))
It turns out that fold_ternary does not convert the type of an integer
while constructing BIT_AND_EXPR.
The patch fixes the problem by calling fold_convert on arg1.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2006-05-21 Kazu Hirata <kazu@codesourcery.com>
PR tree-optimization/26622.
* fold-const.c (fold_ternary) <COND_EXPR>: Call fold_convert
on arg1.
2006-05-21 Kazu Hirata <kazu@codesourcery.com>
PR tree-optimization/26622.
* gcc.c-torture/compile/pr26622.c: New.
Index: fold-const.c
===================================================================
--- fold-const.c (revision 113936)
+++ fold-const.c (working copy)
@@ -11072,8 +11072,10 @@ fold_ternary (enum tree_code code, tree
&& integer_zerop (TREE_OPERAND (arg0, 1))
&& integer_zerop (op2)
&& (tem = sign_bit_p (TREE_OPERAND (arg0, 0), arg1)))
- return fold_convert (type, fold_build2 (BIT_AND_EXPR,
- TREE_TYPE (tem), tem, arg1));
+ return fold_convert (type,
+ fold_build2 (BIT_AND_EXPR,
+ TREE_TYPE (tem), tem,
+ fold_convert (TREE_TYPE (tem), arg1)));
/* (A >> N) & 1 ? (1 << N) : 0 is simply A & (1 << N). A & 1 was
already handled above. */
--- /dev/null 2006-03-11 08:41:44.866675760 -0800
+++ testsuite/gcc.c-torture/compile/pr26622.c 2006-05-20 21:31:54.000000000 -0700
@@ -0,0 +1,11 @@
+/* PR middle-end/26622
+ fold_ternary used to create a tree with mismatching types, causing
+ (const_int 128) to appear in QImode rtx. */
+
+unsigned char g;
+
+unsigned long long
+foo (void)
+{
+ return ((long long) ((g & 0x80) != 0)) << 7;
+}