From 6dc208a1ed88e40e359173ece8a3f9441001fd6c Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 26 Jun 2003 12:37:35 +0200 Subject: [PATCH] re PR rtl-optimization/11210 (optimizer drops conditional with typecast from signed to unsigned char) PR optimization/11210 * fold-const (decode_field_reference): Strip only NOPs that don't affect the sign. From-SVN: r68524 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/20030626-1.c | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/20030626-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e92b4a51933a..fec3aeaadc90 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2003-06-26 Eric Botcazou + + PR optimization/11210 + * fold-const (decode_field_reference): Strip only NOPs that + don't affect the sign. + 2003-06-26 Dhananjay Deshpande * gcc/config/sh/sh.md (push_fpscr): Enable for TARGET_SH2E. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b35d733e220c..b160a4ea0ebe 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2742,7 +2742,8 @@ decode_field_reference (exp, pbitsize, pbitpos, pmode, punsignedp, if (! INTEGRAL_TYPE_P (TREE_TYPE (exp))) return 0; - STRIP_NOPS (exp); + /* Signedness matters here. */ + STRIP_SIGN_NOPS (exp); if (TREE_CODE (exp) == BIT_AND_EXPR) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e5f954145af6..c988401302d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-06-26 Eric Botcazou + + * gcc.dg/20030626-1.c: New test. + 2003-06-26 Neil Booth * const-str-2.m: Update. diff --git a/gcc/testsuite/gcc.dg/20030626-1.c b/gcc/testsuite/gcc.dg/20030626-1.c new file mode 100644 index 000000000000..7d356e0050bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/20030626-1.c @@ -0,0 +1,18 @@ +/* PR optimization/11210 */ +/* Originator: Guido Classen */ +/* Reduced testcase by Falk Hueffner */ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +/* Verify that the constant expressions folder doesn't + throw away the cast operation in the comparison. */ + +struct str { + int head; + char data[8]; +}; + +int foo(struct str t) +{ + return t.data[0] || (unsigned char) t.data[2] != 130; /* { dg-bogus "comparison is always 1" } */ +} -- 2.47.3