Anitha Boyapati <anitha.boyap...@gmail.com> writes:

> int main() {
>         volatile int a, b;
>         if(a>b) return 1;
>         else return 2;
>
> }
>
> Expand  pass shows that "le"operator  is chosen.
>
> (jump_insn 9 8 10 3 gt_int.c:4 (set (pc)
>         (if_then_else (le:CC (cc0)
>                 (const_int 0 [0x0]))
>             (label_ref 14)
>             (pc))) -1 (nil))
>
>
> If I modify the same testcase to use 'float' datatype instead of
> 'int', "gt" operator is picked up.
>
> (jump_insn 9 8 34 3 gt.c:4 (set (pc)
>         (if_then_else (gt:CC (cc0)
>                 (const_int 0 [0x0]))
>             (label_ref 12)
>             (pc))) -1 (nil))
>
>
> I would like to know what prompts gcc to decide if "le" can be used in
> the expand pass rather than "gt" operator. Or more precisely why it
> differs incase of float.

The choice of LE when using int is just a happenstance of the way that
gcc generates code.  When gcc comes to RTL generation it happens to be
looking at an if statement that falls through on true and branches on
else.  So it flips the condition to branch on true (in
do_compare_rtx_and_jump).  The use of volatile doesn't affect this: it
will still only load the variables precisely as described in the
program.

The condition can not be flipped for float because that would be an
invalid transformation if one of the values is NaN.

Ian

Reply via email to