re PR tree-optimization/83269 (Wrong constant folding)
PR tree-optimization/83269 * fold-const.c (fold_binary_loc): Perform (-A) - B -> (-B) - A subtraction in arg0's type if type is signed and arg0 is unsigned. Formatting fix. * gcc.c-torture/execute/pr83269.c: New test. From-SVN: r255729
This commit is contained in:
parent
ea5869d324
commit
99ccf43c70
|
@ -1,5 +1,10 @@
|
||||||
2017-12-15 Jakub Jelinek <jakub@redhat.com>
|
2017-12-15 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
PR tree-optimization/83269
|
||||||
|
* fold-const.c (fold_binary_loc): Perform (-A) - B -> (-B) - A
|
||||||
|
subtraction in arg0's type if type is signed and arg0 is unsigned.
|
||||||
|
Formatting fix.
|
||||||
|
|
||||||
Backported from mainline
|
Backported from mainline
|
||||||
2017-12-14 Jakub Jelinek <jakub@redhat.com>
|
2017-12-14 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
|
|
@ -9123,8 +9123,8 @@ expr_not_equal_to (tree t, const wide_int &w)
|
||||||
return NULL_TREE. */
|
return NULL_TREE. */
|
||||||
|
|
||||||
tree
|
tree
|
||||||
fold_binary_loc (location_t loc,
|
fold_binary_loc (location_t loc, enum tree_code code, tree type,
|
||||||
enum tree_code code, tree type, tree op0, tree op1)
|
tree op0, tree op1)
|
||||||
{
|
{
|
||||||
enum tree_code_class kind = TREE_CODE_CLASS (code);
|
enum tree_code_class kind = TREE_CODE_CLASS (code);
|
||||||
tree arg0, arg1, tem;
|
tree arg0, arg1, tem;
|
||||||
|
@ -9728,10 +9728,17 @@ fold_binary_loc (location_t loc,
|
||||||
case MINUS_EXPR:
|
case MINUS_EXPR:
|
||||||
/* (-A) - B -> (-B) - A where B is easily negated and we can swap. */
|
/* (-A) - B -> (-B) - A where B is easily negated and we can swap. */
|
||||||
if (TREE_CODE (arg0) == NEGATE_EXPR
|
if (TREE_CODE (arg0) == NEGATE_EXPR
|
||||||
&& negate_expr_p (op1))
|
&& negate_expr_p (op1)
|
||||||
return fold_build2_loc (loc, MINUS_EXPR, type,
|
/* If arg0 is e.g. unsigned int and type is int, then this could
|
||||||
negate_expr (op1),
|
introduce UB, because if A is INT_MIN at runtime, the original
|
||||||
fold_convert_loc (loc, type,
|
expression can be well defined while the latter is not.
|
||||||
|
See PR83269. */
|
||||||
|
&& !(ANY_INTEGRAL_TYPE_P (type)
|
||||||
|
&& TYPE_OVERFLOW_UNDEFINED (type)
|
||||||
|
&& ANY_INTEGRAL_TYPE_P (TREE_TYPE (arg0))
|
||||||
|
&& !TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))))
|
||||||
|
return fold_build2_loc (loc, MINUS_EXPR, type, negate_expr (op1),
|
||||||
|
fold_convert_loc (loc, type,
|
||||||
TREE_OPERAND (arg0, 0)));
|
TREE_OPERAND (arg0, 0)));
|
||||||
|
|
||||||
/* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to
|
/* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
2017-12-15 Jakub Jelinek <jakub@redhat.com>
|
2017-12-15 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
PR tree-optimization/83269
|
||||||
|
* gcc.c-torture/execute/pr83269.c: New test.
|
||||||
|
|
||||||
PR tree-optimization/80631
|
PR tree-optimization/80631
|
||||||
* gcc.target/i386/avx2-pr80631.c: New test.
|
* gcc.target/i386/avx2-pr80631.c: New test.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* PR tree-optimization/83269 */
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
#if __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ > 4 && __CHAR_BIT__ == 8
|
||||||
|
volatile unsigned char a = 1;
|
||||||
|
long long b = 0x80000000L;
|
||||||
|
int c = -((int)(-b) - (-0x7fffffff * a));
|
||||||
|
if (c != 1)
|
||||||
|
__builtin_abort ();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue