llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Wrong x86 code generated

Open mmozeiko opened this issue 13 years ago • 9 comments

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.

mmozeiko avatar Dec 10 '12 20:12 mmozeiko

mentioned in issue llvm/llvm-bugzilla-archive#15607

darkbuck avatar Nov 26 '21 17:11 darkbuck

*** Bug llvm/llvm-bugzilla-archive#15607 has been marked as a duplicate of this bug. ***

darkbuck avatar Mar 30 '13 07:03 darkbuck

Committed in r174972.

llvmbot avatar Feb 12 '13 17:02 llvmbot

Patch submitted to Phabricator.

http://llvm-reviews.chandlerc.com/D344 http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130128/163645.html

llvmbot avatar Jan 29 '13 17:01 llvmbot

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(N0.getOperand(1))) {

  •  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.

efriedma-quic avatar Dec 19 '12 07:12 efriedma-quic

modifed example

llvmbot avatar Dec 13 '12 00:12 llvmbot

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

llvmbot avatar Dec 13 '12 00:12 llvmbot

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}

llvmbot avatar Dec 11 '12 11:12 llvmbot

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) ^

llvmbot avatar Dec 11 '12 11:12 llvmbot