This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
SSA value numbering doing better than GCSE?
- To: gcc at gcc dot gnu dot org
- Subject: SSA value numbering doing better than GCSE?
- From: Daniel Berlin <dan at cgsoftware dot com>
- Date: 16 May 2001 23:09:49 -0400
So i'm getting value numbering to do something besides *value
numbering* (IE before, it just value numbered, and didn't do anything
with the result), so i can submit it (and because a few others
have asked about writing SSA optimization passes, and want the CCP and
valnum passes as examples), and i came across the following:
Given this:
int main(int argc, char **argv)
{
int a=50; /* pointless initialization, yes */
int b=30; /* Same here */
if (argc > 1)
{
a=30;
b=30;
}
else
{
a=40;
b=40;
}
printf("%d %d\n", a, b);
}
We get this assembly with -fssa -fssa-valnum -O2:
.file "test20.c"
.section .rodata
.align 2
.LC0:
.string "%d %d\n"
.section ".text"
.align 2
.globl main
.type main,@function
main:
cmpwi 0,3,1
stwu 1,-16(1)
mflr 0
lis 9,.LC0@ha
li 4,30
stw 0,20(1)
la 3,.LC0@l(9)
bgt- 0,.L3
li 4,40
.L3:
mr 5,4
crxor 6,6,6
bl printf
lwz 0,20(1)
addi 1,1,16
mtlr 0
blr
And with just -O2:
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.1 20010516 (experimental)"
.file "test20.c"
.section .rodata
.align 2
.LC0:
.string "%d %d\n"
.section ".text"
.align 2
.globl main
.type main,@function
main:
cmpwi 0,3,1
stwu 1,-16(1)
mflr 0
lis 9,.LC0@ha
li 5,30
li 4,30
stw 0,20(1)
la 3,.LC0@l(9)
bgt- 0,.L3
li 5,40
li 4,40
.L3:
crxor 6,6,6
bl printf
lwz 0,20(1)
addi 1,1,16
mtlr 0
blr
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.1 20010516 (experimental)"
Or, for those who don't feel like looking for the difference:
*** withoutvalnum.s Wed May 16 22:50:58 2001
--- withvalnum.s Wed May 16 22:50:53 2001
*************** main:
*** 12,25 ****
stwu 1,-16(1)
mflr 0
lis 9,.LC0@ha
- li 5,30
li 4,30
stw 0,20(1)
la 3,.LC0@l(9)
bgt- 0,.L3
- li 5,40
li 4,40
.L3:
crxor 6,6,6
bl printf
lwz 0,20(1)
--- 12,24 ----
stwu 1,-16(1)
mflr 0
lis 9,.LC0@ha
li 4,30
stw 0,20(1)
la 3,.LC0@l(9)
bgt- 0,.L3
li 4,40
.L3:
+ mr 5,4
crxor 6,6,6
bl printf
lwz 0,20(1)
I'm curious as to why GCSE (or some other optimization pass) doesn't
do the same thing we just did (This happens in quite a few other
cases, too.) Is the value numbering over strongly connected
components more powerful than our GCSE?
In fact, all we actually did is renumber things by their value
numbers, and let everything else take care of the duplication that
exposes.
--Dan
--
"I plugged my phone in where the blender used to be. I called
someone. They went "Aaaaahhhh..."
"-Steven Wright