This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem regarding canonicalization


I have a combiner pattern that converts a sub-cmp pattern to a cmp insn, something like this -
"if (a-1 < 0)"
is converted to
"if (a<1)"


Now consider the following test case -

<snip>
f(long a){return (--a > 0);}
main(){if(f(0x80000000L)==0)abort();exit(0);}
</snip>

The compiler generates the following code for f()
      cmp     r0, 1   ;;canonicalized
      mov r0,1
      sub.le r0,r0,r0

This works fine under normal circumstances. However, in the testcase, the least negative no. i.e. 0x80000000 (hereafer referred to as MIN) is passed. When 1 is subtracted from MIN, by --a, it becomes positive and the conditions get reversed thus leading to failure during execution.

Similar problem seems to arise when MAX is passed to a function that does "return (++a < 0).

How do I tackle this problem? Anything I may be missing?

Thanks in advance.
Ashwin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]