From 2d079d1884af4a38dba15d1bae87879b53dca431 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Wed, 8 Aug 2012 19:42:58 +0000 Subject: [PATCH] * simplify-rtx.c (simplify_binary_operation_1): Do not simplify IOR to a constant if one operand has side effects. testsuite: * gcc.c-torture/execute/20120808-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@190237 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 ++++ gcc/simplify-rtx.c | 7 +++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.c-torture/execute/20120808-1.c | 37 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/20120808-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b8eb055a202..e8554ecc1a2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2012-08-08 Joseph Myers + + * simplify-rtx.c (simplify_binary_operation_1): Do not simplify + IOR to a constant if one operand has side effects. + 2012-08-08 Ulrich Weigand * builtins.c (expand_builtin_atomic_compare_exchange): Pass old diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 0eed715ccfb..f56a5edef8f 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2420,7 +2420,9 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode, case IOR: if (trueop1 == CONST0_RTX (mode)) return op0; - if (INTEGRAL_MODE_P (mode) && trueop1 == CONSTM1_RTX (mode)) + if (INTEGRAL_MODE_P (mode) + && trueop1 == CONSTM1_RTX (mode) + && !side_effects_p (op0)) return op1; if (rtx_equal_p (trueop0, trueop1) && ! side_effects_p (op0)) return op0; @@ -2434,7 +2436,8 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode, /* (ior A C) is C if all bits of A that might be nonzero are on in C. */ if (CONST_INT_P (op1) && HWI_COMPUTABLE_MODE_P (mode) - && (nonzero_bits (op0, mode) & ~UINTVAL (op1)) == 0) + && (nonzero_bits (op0, mode) & ~UINTVAL (op1)) == 0 + && !side_effects_p (op0)) return op1; /* Canonicalize (X & C1) | C2. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bd2e3f37268..2465d80ef5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2012-08-08 Joseph Myers + + * gcc.c-torture/execute/20120808-1.c: New test. + 2012-08-08 H.J. Lu PR rtl-optimization/54157 diff --git a/gcc/testsuite/gcc.c-torture/execute/20120808-1.c b/gcc/testsuite/gcc.c-torture/execute/20120808-1.c new file mode 100644 index 00000000000..3cbab2ba843 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20120808-1.c @@ -0,0 +1,37 @@ +extern void exit (int); +extern void abort (void); + +volatile int i; +unsigned char *volatile cp; +unsigned char d[32] = { 0 }; + +int +main (void) +{ + unsigned char c[32] = { 0 }; + unsigned char *p = d + i; + int j; + for (j = 0; j < 30; j++) + { + int x = 0xff; + int y = *++p; + switch (j) + { + case 1: x ^= 2; break; + case 2: x ^= 4; break; + case 25: x ^= 1; break; + default: break; + } + c[j] = y | x; + cp = p; + } + if (c[0] != 0xff + || c[1] != 0xfd + || c[2] != 0xfb + || c[3] != 0xff + || c[4] != 0xff + || c[25] != 0xfe + || cp != d + 30) + abort (); + exit (0); +} -- 2.11.4.GIT