From 45d34fe35846eed7019bdc2f7814025302849e0c Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Sun, 19 Jul 2009 19:09:59 +0000 Subject: [PATCH] Fix http://llvm.org/bugs/show_bug.cgi?id=4583 Inline asm instructions may have additional register operands. These operands are not marked with a flag like the normal asm operands, so we must not assert that there is a flag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76373 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineInstr.cpp | 8 ++++++-- test/CodeGen/X86/2009-07-19-AsmExtraOperands.ll | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/X86/2009-07-19-AsmExtraOperands.ll diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index c6f3e319f2f..8deaa1a35d7 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -732,7 +732,9 @@ isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx) const { unsigned DefPart = 0; for (unsigned i = 1, e = getNumOperands(); i < e; ) { const MachineOperand &FMO = getOperand(i); - assert(FMO.isImm()); + // After the normal asm operands there may be additional imp-def regs. + if (!FMO.isImm()) + return false; // Skip over this def. unsigned NumOps = InlineAsm::getNumOperandRegisters(FMO.getImm()); unsigned PrevDef = i + 1; @@ -788,7 +790,9 @@ isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx) const { unsigned FlagIdx, NumOps=0; for (FlagIdx = 1; FlagIdx < UseOpIdx; FlagIdx += NumOps+1) { const MachineOperand &UFMO = getOperand(FlagIdx); - assert(UFMO.isImm() && "Expecting flag operand on inline asm"); + // After the normal asm operands there may be additional imp-def regs. + if (!UFMO.isImm()) + return false; NumOps = InlineAsm::getNumOperandRegisters(UFMO.getImm()); assert(NumOps < getNumOperands() && "Invalid inline asm flag"); if (UseOpIdx < FlagIdx+NumOps+1) diff --git a/test/CodeGen/X86/2009-07-19-AsmExtraOperands.ll b/test/CodeGen/X86/2009-07-19-AsmExtraOperands.ll new file mode 100644 index 00000000000..31322cfcf93 --- /dev/null +++ b/test/CodeGen/X86/2009-07-19-AsmExtraOperands.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | llc -march=x86-64 +; PR4583 + +define i32 @atomic_cmpset_long(i64* %dst, i64 %exp, i64 %src) nounwind ssp noredzone noimplicitfloat { +entry: + %0 = call i8 asm sideeffect "\09lock ; \09\09\09cmpxchgq $2,$1 ;\09 sete\09$0 ;\09\091:\09\09\09\09# atomic_cmpset_long", "={ax},=*m,r,{ax},*m,~{memory},~{dirflag},~{fpsr},~{flags}"(i64* undef, i64 undef, i64 undef, i64* undef) nounwind ; [#uses=0] + br label %1 + +;