fold-const.c (fold_unary): Fold (T1)(~(T2)X) as ~(T1)X...
* fold-const.c (fold_unary) <NOP_EXPR>: Fold (T1)(~(T2)X) as ~(T1)X, when T1 and T2 are integer types of the same precision and (T2)X isn't an extension. * gcc.dg/fold-convnotconv-1.c: New test case. From-SVN: r112455
This commit is contained in:
parent
792617a52a
commit
e8206491f0
4 changed files with 43 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2006-03-28 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* fold-const.c (fold_unary) <NOP_EXPR>: Fold (T1)(~(T2)X) as
|
||||
~(T1)X, when T1 and T2 are integer types of the same precision
|
||||
and (T2)X isn't an extension.
|
||||
|
||||
2006-03-28 Jeff Law <law@redhat.com>
|
||||
|
||||
PR tree-optimization/26796
|
||||
|
|
|
@ -7074,6 +7074,22 @@ fold_unary (enum tree_code code, tree type, tree op0)
|
|||
TREE_OPERAND (arg0, 1));
|
||||
}
|
||||
|
||||
/* Convert (T1)(~(T2)X) into ~(T1)X if T1 and T2 are integral types
|
||||
of the same precision, and X is a integer type not narrower than
|
||||
types T1 or T2, i.e. the cast (T2)X isn't an extension. */
|
||||
if (INTEGRAL_TYPE_P (type)
|
||||
&& TREE_CODE (op0) == BIT_NOT_EXPR
|
||||
&& INTEGRAL_TYPE_P (TREE_TYPE (op0))
|
||||
&& (TREE_CODE (TREE_OPERAND (op0, 0)) == NOP_EXPR
|
||||
|| TREE_CODE (TREE_OPERAND (op0, 0)) == CONVERT_EXPR)
|
||||
&& TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0)))
|
||||
{
|
||||
tem = TREE_OPERAND (TREE_OPERAND (op0, 0), 0);
|
||||
if (INTEGRAL_TYPE_P (TREE_TYPE (tem))
|
||||
&& TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (tem)))
|
||||
return fold_build1 (BIT_NOT_EXPR, type, fold_convert (type, tem));
|
||||
}
|
||||
|
||||
tem = fold_convert_const (code, type, arg0);
|
||||
return tem ? tem : NULL_TREE;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2006-03-28 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* gcc.dg/fold-convnotconv-1.c: New test case.
|
||||
|
||||
2006-03-28 Paul Thomas <pault@gcc.gnu.org>
|
||||
|
||||
PR fortran/26779
|
||||
|
|
17
gcc/testsuite/gcc.dg/fold-convnotconv-1.c
Normal file
17
gcc/testsuite/gcc.dg/fold-convnotconv-1.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -fdump-tree-original" } */
|
||||
|
||||
int test1(int a)
|
||||
{
|
||||
return ~(unsigned int)a;
|
||||
}
|
||||
|
||||
unsigned int test2(unsigned int b)
|
||||
{
|
||||
return ~(int)b;
|
||||
}
|
||||
|
||||
/* { dg-final { scan-tree-dump-times "~a" 1 "original" } } */
|
||||
/* { dg-final { scan-tree-dump-times "~b" 1 "original" } } */
|
||||
/* { dg-final { cleanup-tree-dump "original" } } */
|
||||
|
Loading…
Add table
Reference in a new issue