Skip to content

Commit aa17d31

Browse files
committed
[X86] Remove FP0-6 operands from call instructions in FPStackifier pass. Only count defs as returns.
All FP0-6 operands should be removed by the FP stackifier. By removing these we fix the machine verifier error in PR39437. I've also made it so that only defs are counted for STReturns which removes what I think were extra stack cleanup instructions. And I've removed the regcall assert because it was checking the attributes of the caller, but here we're concerned with the attributes of the callee. But I don't know how to get that information from this level.
1 parent 98856b2 commit aa17d31

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

llvm/lib/Target/X86/X86FloatingPoint.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -976,22 +976,24 @@ void FPS::shuffleStackTop(const unsigned char *FixStack,
976976
//===----------------------------------------------------------------------===//
977977

978978
void FPS::handleCall(MachineBasicBlock::iterator &I) {
979+
MachineInstr &MI = *I;
979980
unsigned STReturns = 0;
980981
const MachineFunction* MF = I->getParent()->getParent();
981982

982-
for (const auto &MO : I->operands()) {
983-
if (!MO.isReg())
983+
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
984+
MachineOperand &Op = MI.getOperand(i);
985+
if (!Op.isReg() || Op.getReg() < X86::FP0 || Op.getReg() > X86::FP6)
984986
continue;
985987

986-
unsigned R = MO.getReg() - X86::FP0;
988+
assert(Op.isImplicit() && "Expected implicit def/use");
987989

988-
if (R < 8) {
989-
if (MF->getFunction().getCallingConv() != CallingConv::X86_RegCall) {
990-
assert(MO.isDef() && MO.isImplicit());
991-
}
990+
if (Op.isDef())
991+
STReturns |= 1 << getFPReg(Op);
992992

993-
STReturns |= 1 << R;
994-
}
993+
// Remove the operand so that later passes don't see it.
994+
MI.RemoveOperand(i);
995+
--i;
996+
--e;
995997
}
996998

997999
unsigned N = countTrailingOnes(STReturns);

llvm/test/CodeGen/X86/avx512-regcall-NoMask.ll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39437.
3-
; RUN: llc < %s -mtriple=i386-pc-win32 -mattr=+avx512f -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -verify-machineinstrs=0 | FileCheck %s --check-prefix=X32
4-
; RUN: llc < %s -mtriple=x86_64-win32 -mattr=+avx512f -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -verify-machineinstrs=0 | FileCheck %s --check-prefix=WIN64
5-
; RUN: llc < %s -mtriple=x86_64-linux-gnu -mattr=+avx512f -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -verify-machineinstrs=0 | FileCheck %s --check-prefix=LINUXOSX64
2+
; RUN: llc < %s -mtriple=i386-pc-win32 -mattr=+avx512f -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -verify-machineinstrs | FileCheck %s --check-prefix=X32
3+
; RUN: llc < %s -mtriple=x86_64-win32 -mattr=+avx512f -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -verify-machineinstrs | FileCheck %s --check-prefix=WIN64
4+
; RUN: llc < %s -mtriple=x86_64-linux-gnu -mattr=+avx512f -mattr=+avx512vl -mattr=+avx512bw -mattr=+avx512dq -verify-machineinstrs | FileCheck %s --check-prefix=LINUXOSX64
65

76
; Test regcall when receiving/returning i1
87
define x86_regcallcc i1 @test_argReti1(i1 %a) {
@@ -604,7 +603,6 @@ define x86_regcallcc double @test_CallargParamf80(x86_fp80 %a) {
604603
; X32-NEXT: fadd %st, %st(0)
605604
; X32-NEXT: calll _test_argParamf80
606605
; X32-NEXT: vaddsd %xmm0, %xmm0, %xmm0
607-
; X32-NEXT: fstp %st(0)
608606
; X32-NEXT: popl %esp
609607
; X32-NEXT: retl
610608
;
@@ -616,7 +614,6 @@ define x86_regcallcc double @test_CallargParamf80(x86_fp80 %a) {
616614
; WIN64-NEXT: fadd %st, %st(0)
617615
; WIN64-NEXT: callq test_argParamf80
618616
; WIN64-NEXT: vaddsd %xmm0, %xmm0, %xmm0
619-
; WIN64-NEXT: fstp %st(0)
620617
; WIN64-NEXT: popq %rsp
621618
; WIN64-NEXT: retq
622619
; WIN64-NEXT: .seh_handlerdata
@@ -631,7 +628,6 @@ define x86_regcallcc double @test_CallargParamf80(x86_fp80 %a) {
631628
; LINUXOSX64-NEXT: fadd %st, %st(0)
632629
; LINUXOSX64-NEXT: callq test_argParamf80
633630
; LINUXOSX64-NEXT: vaddsd %xmm0, %xmm0, %xmm0
634-
; LINUXOSX64-NEXT: fstp %st(0)
635631
; LINUXOSX64-NEXT: popq %rsp
636632
; LINUXOSX64-NEXT: .cfi_def_cfa_offset 8
637633
; LINUXOSX64-NEXT: retq

0 commit comments

Comments
 (0)