Wrong x86 code generated
| Bugzilla Link | 14562 |
| Resolution | FIXED |
| Resolved on | Mar 30, 2013 00:52 |
| Version | trunk |
| OS | All |
| Attachments | code to reproduce |
| CC | @efriedma-quic |
Extended Description
Attached C code generates invalid X86 assembly. LLVM IL code looks fine. Code should print out 0, but instead prints out garbage (I assume some value from stack). Code generated for x86_64 is correct.
mentioned in issue llvm/llvm-bugzilla-archive#15607
*** Bug llvm/llvm-bugzilla-archive#15607 has been marked as a duplicate of this bug. ***
Committed in r174972.
Patch submitted to Phabricator.
http://llvm-reviews.chandlerc.com/D344 http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130128/163645.html
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp (revision 170478)
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp (working copy)
@@ -5089,8 +5089,10 @@
if (ShAmt == 0 && N0.getOpcode() == ISD::SHL && N0.hasOneUse() &&
ExtVT == VT && TLI.isNarrowingProfitable(N0.getValueType(), VT)) {
if (ConstantSDNode *N01 = dyn_cast
-
ShLeftAmt = N01->getZExtValue(); -
N0 = N0.getOperand(0);
-
if (N01->getZExtValue() < VT.getSizeInBits()) { -
ShLeftAmt = N01->getZExtValue(); -
N0 = N0.getOperand(0); -
} }}
I don't have time to finish this patch right now.
This seems to happen only with -O0.
Making temp1 a global (pr14562x.c, attached) shows the problem more explicitly -- there is no store to the low half:
.loc 1 5 5 prologue_end # pr14562x.c:5:5
.Ltmp2: movl $0, temp1+4 .loc 1 6 1 # pr14562x.c:6:1 addl $12, %esp ret
Assuming the testcase is C++...
It seems wrong in x86 codegen.
$ clang -m32 pr14562.cc -O0 -S -emit-llvm -o - | llc -march=x86 -O{any}
This is not standard C:
$ clang -S -O4 pr14562.c -o - pr14562.c:1:58: error: expected ')' static void foo(unsigned long long a0, unsigned long long& a1) ^