[Bug c++/79002] New: Weird c++ assembly code generated for tail call
vogt at linux dot vnet.ibm.com
gcc-bugzilla@gcc.gnu.org
Thu Jan 5 12:23:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79002
Bug ID: 79002
Summary: Weird c++ assembly code generated for tail call
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vogt at linux dot vnet.ibm.com
Target Milestone: ---
Target: s390x
G++ (r244001) generates some pretty weird assembly code on s390x for this test
case. (Note that j is not initialised and I couldn't find a variant of this
test case where it is).
-- test.C --
int g;
unsigned char *p;
void r1()
{
int i;
int j;
i = *p;
if (j <= g || (i) != 1) // <---- note: parentheses around (i)
r1();
}
------------
$ gcc -O3 -march=z10 -mzarch -m64 -S test.C
$ cat test.s
--
_Z2r1v:
lgrl %r2,p <-- r2 := &p
lrl %r1,g <-- r1 := &g
llc %r2,0(%r2) <-- r2 := *r2
.L5:
cijlh %r2,1,.L2 <-- compare with immediate and jump if !=
.L4:
cijhe %r1,0,.L11 <-- ... if >=
.L1:
br %r14
.L11:
cijl %r1,0,.L1 <-- ... if <
cijl %r1,0,.L1
cijhe %r1,0,.L4
br %r14
.L2:
cijl %r1,0,.L5
cijl %r1,0,.L5
j .L2
--
If the parentheses are removed from "(i)", the result is sane:
...
if (j <= g || i != 1) // <---- note: no parentheses around i
...
--
_Z2r1v:
lgrl %r2,p
lrl %r1,g
llc %r2,0(%r2)
.L2:
cijhe %r1,0,.L2
cijlh %r2,1,.L2
br %r14
--
Not tested on other targets, but to me it looks like a general C++ problem
(does not happen with the C compiler, at least not with this test case). While
the generated code is valid, this effect makes reducing test cases from the
Spec2006 suite harder (there are variants of the code that result in even more
unnecessary labels and assembly code). It might be possible to trigger this
without relying on undefined variables.
More information about the Gcc-bugs
mailing list