Skip to content

Commit 3518f93

Browse files
committed
Insert trap for 64-bit offsets on X86 32-bit targets
This prevents the verify instruction pass from reporting the offsets as erroneous when we've already reported the error to the user. Add `-verify-machineinstrs` to tests for large displacements to catch simliar issues.
1 parent 85d98f0 commit 3518f93

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

llvm/lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,15 +959,15 @@ X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
959959
}
960960

961961
if (MI.getOperand(FIOperandNum+3).isImm()) {
962+
const X86InstrInfo *TII = MF.getSubtarget<X86Subtarget>().getInstrInfo();
963+
const DebugLoc &DL = MI.getDebugLoc();
962964
int64_t Imm = MI.getOperand(FIOperandNum + 3).getImm();
963965
int64_t Offset = FIOffset + Imm;
964966
bool FitsIn32Bits = isInt<32>(Offset);
965967
// If the offset will not fit in a 32-bit displacement, then for 64-bit
966968
// targets, scavenge a register to hold it. Otherwise...
967969
if (Is64Bit && !FitsIn32Bits) {
968970
assert(RS && "RegisterScavenger was NULL");
969-
const X86InstrInfo *TII = MF.getSubtarget<X86Subtarget>().getInstrInfo();
970-
const DebugLoc &DL = MI.getDebugLoc();
971971

972972
RS->enterBasicBlockEnd(MBB);
973973
RS->backward(std::next(II));
@@ -987,8 +987,12 @@ X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
987987
}
988988

989989
// ... for 32-bit targets, this is a bug!
990-
if (!Is64Bit && !FitsIn32Bits)
990+
if (!Is64Bit && !FitsIn32Bits) {
991991
MI.emitGenericError("64-bit offset calculated but target is 32-bit");
992+
// Trap so that the instruction verification pass does not fail if run.
993+
BuildMI(MBB, MBBI, DL, TII->get(X86::TRAP));
994+
return false;
995+
}
992996

993997
if (Offset != 0 || !tryOptimizeLEAtoMOV(II))
994998
MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);

llvm/test/CodeGen/X86/avx512f-large-stack.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --no_x86_scrub_sp --version 4
2-
; RUN: llc -O0 -mtriple=x86_64 -mattr=+avx512f < %s | FileCheck %s --check-prefix=CHECK
2+
; RUN: llc -O0 -mtriple=x86_64 -mattr=+avx512f -verify-machineinstrs < %s | FileCheck %s --check-prefix=CHECK
33
define void @f(i16 %LGV2, i1 %LGV3) {
44
; CHECK-LABEL: f:
55
; CHECK: # %bb.0: # %BB

llvm/test/CodeGen/X86/large-displacements-fastisel.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2-
; RUN: llc < %s -mtriple=x86_64 -O=0 | FileCheck %s
2+
; RUN: llc < %s -mtriple=x86_64 -O=0 -verify-machineinstrs | FileCheck %s
33
@G = global i8 0
44

55
; Regression test for PR113856 - incorrect FastISel assert

llvm/test/CodeGen/X86/large-displacements.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: not llc < %s -mtriple=i686 -filetype=null 2>&1 | FileCheck %s -check-prefix=ERR-i686
2-
; RUN: llc < %s -mtriple=x86_64 | FileCheck %s -check-prefix=x86_64
1+
; RUN: not llc < %s -mtriple=i686 -filetype=null -verify-machineinstrs 2>&1 | FileCheck %s -check-prefix=ERR-i686
2+
; RUN: llc < %s -mtriple=x86_64 -verify-machineinstrs | FileCheck %s -check-prefix=x86_64
33

44
; Regression test for #121932, #113856, #106352, #69365, #25051 which are caused by
55
; an incorrectly written assertion for 64-bit offsets when compiling for 32-bit X86.

0 commit comments

Comments
 (0)