https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94802
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |uros at gcc dot gnu.org
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So shall we deal with that at the RTL level instead then?
Given testcase1:
/* PR tree-optimization/94802 */
/* { dg-do compile } */
/* { dg-options "-O2" } */
void foo (void);
int
f1 (int a, int b)
{
return (a - b) >= 0;
}
int
f2 (int a, int b)
{
return (a - b) > 0;
}
int
f3 (int a, int b)
{
return (a - b) <= 0;
}
int
f4 (int a, int b)
{
return (a - b) < 0;
}
void
f5 (int a, int b)
{
if ((a - b) >= 0)
foo ();
}
void
f6 (int a, int b)
{
if ((a - b) > 0)
foo ();
}
void
f7 (int a, int b)
{
if ((a - b) <= 0)
foo ();
}
void
f8 (int a, int b)
{
if ((a - b) < 0)
foo ();
}
and testcase2, it would be nice to emit the same or at least as good as code
for the first one as for the second one, but the testcase1 to testcase2
difference is:
@@ -6,10 +6,9 @@
f1:
.LFB0:
.cfi_startproc
- subl %esi, %edi
- notl %edi
- movl %edi, %eax
- shrl $31, %eax
+ xorl %eax, %eax
+ cmpl %esi, %edi
+ setge %al
ret
.cfi_endproc
.LFE0:
@@ -20,9 +19,8 @@ f1:
f2:
.LFB1:
.cfi_startproc
- subl %esi, %edi
xorl %eax, %eax
- testl %edi, %edi
+ cmpl %esi, %edi
setg %al
ret
.cfi_endproc
@@ -34,9 +32,8 @@ f2:
f3:
.LFB2:
.cfi_startproc
- subl %esi, %edi
xorl %eax, %eax
- testl %edi, %edi
+ cmpl %esi, %edi
setle %al
ret
.cfi_endproc
@@ -48,9 +45,9 @@ f3:
f4:
.LFB3:
.cfi_startproc
- subl %esi, %edi
- movl %edi, %eax
- shrl $31, %eax
+ xorl %eax, %eax
+ cmpl %esi, %edi
+ setl %al
ret
.cfi_endproc
.LFE3:
@@ -62,7 +59,7 @@ f5:
.LFB4:
.cfi_startproc
cmpl %esi, %edi
- jns .L8
+ jge .L8
ret
.p2align 4,,10
.p2align 3
@@ -77,8 +74,7 @@ f5:
f6:
.LFB5:
.cfi_startproc
- subl %esi, %edi
- testl %edi, %edi
+ cmpl %esi, %edi
jg .L11
ret
.p2align 4,,10
@@ -94,8 +90,7 @@ f6:
f7:
.LFB6:
.cfi_startproc
- subl %esi, %edi
- testl %edi, %edi
+ cmpl %esi, %edi
jle .L14
ret
.p2align 4,,10
@@ -112,7 +107,7 @@ f8:
.LFB7:
.cfi_startproc
cmpl %esi, %edi
- js .L17
+ jl .L17
ret
.p2align 4,,10
.p2align 3
We have *cmp<mode>_minus_1 that handles some of this, but not everything.
And now that I think more about it, it can't be done at the RTL level, because
we've lost the information that the subtraction has undefined overflow; when it
overflows, it has different behavior.