public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
[not found] <bug-30521-4@http.gcc.gnu.org/bugzilla/>
@ 2012-03-04 1:45 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-03-04 1:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-03-04 01:44:32 UTC ---
We could do this at the tree level. First do add a late PHIOPT which does the
conversion to a COND_EXPR and then simplify a?b+1:b into a+b. Likewise for
a?b+2:b+1 to a+b+1.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
` (5 preceding siblings ...)
2008-11-22 10:05 ` steven at gcc dot gnu dot org
@ 2008-11-22 10:17 ` bonzini at gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: bonzini at gnu dot org @ 2008-11-22 10:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from bonzini at gnu dot org 2008-11-22 10:15 -------
Subject: Re: "if (i == n) ++i;" or "i += i == n;"?
> The form of the code before CSE is caught in noce_try_addcc. The second form
> obviously not (because we don't know that the value of i.20 is "i + 1").
>
> So this comes down to a pass ordering problem.
I'll just point out that the df merge allowed much better freedom in
pass ordering. Ifconv1 could be anticipated before CSE and fwprop.
Paolo
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
` (4 preceding siblings ...)
2008-11-22 9:53 ` steven at gcc dot gnu dot org
@ 2008-11-22 10:05 ` steven at gcc dot gnu dot org
2008-11-22 10:17 ` bonzini at gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-11-22 10:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from steven at gcc dot gnu dot org 2008-11-22 10:04 -------
Ah, now I see what Pinski meant at comment #2.
Before CSE, we still have the original code for f1:
unsigned int f(unsigned int i, unsigned int n)
{
i.20 = i + 1;
if (i.20 == n) i.20 = i.20 + 1;
return i.20;
}
After CSE (but before the first if-conversion pass) it's been transformed to:
unsigned int f(unsigned int i, unsigned int n)
{
i.20 = i + 1;
if (i.20 == n) i.20 = i + 2;
return i.20;
}
The form of the code before CSE is caught in noce_try_addcc. The second form
obviously not (because we don't know that the value of i.20 is "i + 1").
So this comes down to a pass ordering problem. Or, one could argue that CSE
should not perform this transformation if (say) "i.20 = i + 1" is not made dead
code by the transformation to "i.20 = i + 2".
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
` (3 preceding siblings ...)
2008-08-27 4:40 ` bonzini at gnu dot org
@ 2008-11-22 9:53 ` steven at gcc dot gnu dot org
2008-11-22 10:05 ` steven at gcc dot gnu dot org
2008-11-22 10:17 ` bonzini at gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-11-22 9:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from steven at gcc dot gnu dot org 2008-11-22 09:51 -------
I created a t.c with both functions in it:
unsigned int f1(unsigned int i, unsigned int n) {++i; if (i == n) ++i; return
i;}
unsigned int f2(unsigned int i, unsigned int n) {++i; i += i == n; return i;}
With today's trunk on x86_64, I get:
.file "t.c"
.text
.align 16
.globl f1
.type f1, @function
f1:
.LFB0:
leal 1(%rdi), %eax
addl $2, %edi
cmpl %esi, %eax
cmove %edi, %eax
ret
.LFE0:
.size f1, .-f1
.align 16
.globl f2
.type f2, @function
f2:
.LFB1:
addl $1, %edi
xorl %eax, %eax
cmpl %esi, %edi
sete %al
addl %edi, %eax
ret
.LFE1:
.size f2, .-f2
.section .eh_frame,"aw",@progbits
.Lframe1:
.long .LECIE1-.LSCIE1
.LSCIE1:
.long 0x0
.byte 0x1
.string "zR"
.byte 0x1
.byte 0x78
.byte 0x10
.byte 0x1
.byte 0x3
.byte 0xc
.byte 0x7
.byte 0x8
.byte 0x11
.byte 0x10
.byte 0x1
.align 8
.LECIE1:
.LSFDE1:
.long .LEFDE1-.LASFDE1
.LASFDE1:
.long .LASFDE1-.Lframe1
.long .LFB0
.long .LFE0-.LFB0
.byte 0x0
.align 8
.LEFDE1:
.LSFDE3:
.long .LEFDE3-.LASFDE3
.LASFDE3:
.long .LASFDE3-.Lframe1
.long .LFB1
.long .LFE1-.LFB1
.byte 0x0
.align 8
.LEFDE3:
.ident "GCC: (GNU) 4.4.0 20081122 (experimental) [trunk revision
142117]"
.section .note.GNU-stack,"",@progbits
So still not the same functions.
For x86 (32bit) with -march=core2, I get similar code (f1 with a cmove).
Without a -march option, I get code with a jump.
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2007-01-22 00:29:40 |2008-11-22 09:51:57
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
` (2 preceding siblings ...)
2008-08-27 4:40 ` bonzini at gnu dot org
@ 2008-08-27 4:40 ` bonzini at gnu dot org
2008-11-22 9:53 ` steven at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: bonzini at gnu dot org @ 2008-08-27 4:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from bonzini at gnu dot org 2008-08-27 04:40 -------
*** Bug 37240 has been marked as a duplicate of this bug. ***
--
bonzini at gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bonzini at gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
2007-01-21 8:54 ` [Bug middle-end/30521] " pinskia at gcc dot gnu dot org
2007-01-22 0:29 ` pinskia at gcc dot gnu dot org
@ 2008-08-27 4:40 ` bonzini at gnu dot org
2008-08-27 4:40 ` bonzini at gnu dot org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: bonzini at gnu dot org @ 2008-08-27 4:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bonzini at gnu dot org 2008-08-27 04:40 -------
see PR37240 for another testcase.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
2007-01-21 8:54 ` [Bug middle-end/30521] " pinskia at gcc dot gnu dot org
@ 2007-01-22 0:29 ` pinskia at gcc dot gnu dot org
2008-08-27 4:40 ` bonzini at gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-22 0:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-01-22 00:29 -------
CSE is pushing i+=1; down into the conditional which causes ifcvt not to catch
the if(i) i+=1;.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
GCC target triplet| |i?86-linux
Keywords| |missed-optimization
Last reconfirmed|0000-00-00 00:00:00 |2007-01-22 00:29:40
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"?
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
@ 2007-01-21 8:54 ` pinskia at gcc dot gnu dot org
2007-01-22 0:29 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-21 8:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-01-21 08:54 -------
I think this has been fixed already, for PPC with 4.0.2, we get:
_f:
mr r2,r3
addi r3,r3,1
cmpw cr7,r3,r4
bnelr cr7
addi r3,r2,2
blr
.align 2
.p2align 4,,15
.globl _f1
_f1:
addi r3,r3,1
xor r0,r3,r4
subfic r0,r0,0
addze r0,r3
mr r3,r0
blr
While on the trunk we get:
_f:
addi r3,r3,1
xor r0,r3,r4
subfic r0,r0,0
addze r0,r3
mr r3,r0
blr
.align 2
.globl _f1
_f1:
addi r3,r3,1
xor r0,r3,r4
subfic r0,r0,0
addze r0,r3
mr r3,r0
blr
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30521
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-03-04 1:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-30521-4@http.gcc.gnu.org/bugzilla/>
2012-03-04 1:45 ` [Bug middle-end/30521] "if (i == n) ++i;" or "i += i == n;"? pinskia at gcc dot gnu.org
2007-01-21 0:32 [Bug c++/30521] New: " sigra at home dot se
2007-01-21 8:54 ` [Bug middle-end/30521] " pinskia at gcc dot gnu dot org
2007-01-22 0:29 ` pinskia at gcc dot gnu dot org
2008-08-27 4:40 ` bonzini at gnu dot org
2008-08-27 4:40 ` bonzini at gnu dot org
2008-11-22 9:53 ` steven at gcc dot gnu dot org
2008-11-22 10:05 ` steven at gcc dot gnu dot org
2008-11-22 10:17 ` bonzini at gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).