diff --git a/llvm/lib/Target/X86/X86FloatingPoint.cpp b/llvm/lib/Target/X86/X86FloatingPoint.cpp index c282dc009475..37027ee8beba 100644 --- a/llvm/lib/Target/X86/X86FloatingPoint.cpp +++ b/llvm/lib/Target/X86/X86FloatingPoint.cpp @@ -991,13 +991,16 @@ void FPS::handleSpecialFP(MachineBasicBlock::iterator &I) { case X86::FpSET_ST0_32: case X86::FpSET_ST0_64: case X86::FpSET_ST0_80: { - unsigned RegOnTop = getStackEntry(0); + unsigned Op0 = getFPReg(MI->getOperand(0)); + // FpSET_ST0_80 is generated by copyRegToReg for both function return // and inline assembly with the "st" constrain. In the latter case, // it is possible for ST(0) to be alive after this instruction. - if (!MI->killsRegister(X86::FP0 + RegOnTop)) { - // Duplicate ST0 + if (!MI->killsRegister(X86::FP0 + Op0)) { + // Duplicate Op0 duplicateToTop(0, 7 /*temp register*/, I); + } else { + moveToTop(Op0, I); } --StackTop; // "Forget" we have something on the top of stack! break; diff --git a/llvm/test/CodeGen/X86/inline-asm-fpstack4.ll b/llvm/test/CodeGen/X86/inline-asm-fpstack4.ll index 24a63537fcf8..c9122fad6cf7 100644 --- a/llvm/test/CodeGen/X86/inline-asm-fpstack4.ll +++ b/llvm/test/CodeGen/X86/inline-asm-fpstack4.ll @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | llc -march=x86 > %t +; RUN: llvm-as < %s | llc -march=x86 ; PR4484 declare x86_fp80 @ceil() diff --git a/llvm/test/CodeGen/X86/inline-asm-fpstack5.ll b/llvm/test/CodeGen/X86/inline-asm-fpstack5.ll new file mode 100644 index 000000000000..64f3788f45dd --- /dev/null +++ b/llvm/test/CodeGen/X86/inline-asm-fpstack5.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as < %s | llc -march=x86 +; PR4485 + +define void @test(x86_fp80* %a) { +entry: + %0 = load x86_fp80* %a, align 16 + %1 = fmul x86_fp80 %0, 0xK4006B400000000000000 + %2 = fmul x86_fp80 %1, 0xK4012F424000000000000 + tail call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %2) + %3 = load x86_fp80* %a, align 16 + %4 = fmul x86_fp80 %3, 0xK4006B400000000000000 + %5 = fmul x86_fp80 %4, 0xK4012F424000000000000 + tail call void asm sideeffect "fistpl $0", "{st},~{st}"(x86_fp80 %5) + ret void +}