Skip to content

Commit 8d3ae64

Browse files
committed
Recommit "[X86] Increase the number of instructions searched for isSafeToClobberEFLAGS in a couple places"
I messed up the bug numbers in the commit message before Previously this function searched 4 instructions forwards or backwards to determine if it was ok to clobber eflags. This is called in 3 places: rematerialization, turning 2 operand leas into adds or splitting 3 ops leas into an lea and add on some CPU targets. This patch increases the search limit to 10 instructions for rematerialization and 2 operand lea to add. I've left the old treshold for 3 ops lea spliting as that increases code size. Fixes PR47024 and PR46315.
1 parent 761f568 commit 8d3ae64

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

llvm/lib/Target/X86/X86FixupLEAs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ bool FixupLEAPass::optTwoAddrLEA(MachineBasicBlock::iterator &I,
376376
const MachineOperand &Segment = MI.getOperand(1 + X86::AddrSegmentReg);
377377

378378
if (Segment.getReg() != 0 || !Disp.isImm() || Scale.getImm() > 1 ||
379-
!TII->isSafeToClobberEFLAGS(MBB, I))
379+
!TII->isSafeToClobberEFLAGS(MBB, I, 10))
380380
return false;
381381

382382
Register DestReg = MI.getOperand(0).getReg();

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ void X86InstrInfo::reMaterialize(MachineBasicBlock &MBB,
11271127
const MachineInstr &Orig,
11281128
const TargetRegisterInfo &TRI) const {
11291129
bool ClobbersEFLAGS = Orig.modifiesRegister(X86::EFLAGS, &TRI);
1130-
if (ClobbersEFLAGS && !isSafeToClobberEFLAGS(MBB, I)) {
1130+
if (ClobbersEFLAGS && !isSafeToClobberEFLAGS(MBB, I, 10)) {
11311131
// The instruction clobbers EFLAGS. Re-materialize as MOV32ri to avoid side
11321132
// effects.
11331133
int Value;

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ class X86InstrInfo final : public X86GenInstrInfo {
442442
/// conservative. If it cannot definitely determine the safety after visiting
443443
/// a few instructions in each direction it assumes it's not safe.
444444
bool isSafeToClobberEFLAGS(MachineBasicBlock &MBB,
445-
MachineBasicBlock::iterator I) const {
446-
return MBB.computeRegisterLiveness(&RI, X86::EFLAGS, I, 4) ==
445+
MachineBasicBlock::iterator I,
446+
unsigned Neighborhood = 4) const {
447+
return MBB.computeRegisterLiveness(&RI, X86::EFLAGS, I, Neighborhood) ==
447448
MachineBasicBlock::LQR_Dead;
448449
}
449450

llvm/test/CodeGen/X86/optimize-max-0.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ define void @foo(i8* %r, i32 %s, i32 %w, i32 %x, i8* %j, i32 %d) nounwind {
8585
; CHECK-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %eax ## 4-byte Reload
8686
; CHECK-NEXT: addl %ecx, %eax
8787
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %esi
88-
; CHECK-NEXT: leal 2(%esi), %esi
88+
; CHECK-NEXT: addl $2, %esi
8989
; CHECK-NEXT: movl %esi, {{[-0-9]+}}(%e{{[sb]}}p) ## 4-byte Spill
9090
; CHECK-NEXT: movl (%esp), %esi ## 4-byte Reload
9191
; CHECK-NEXT: addl %esi, %ecx
@@ -513,7 +513,7 @@ define void @bar(i8* %r, i32 %s, i32 %w, i32 %x, i8* %j, i32 %d) nounwind {
513513
; CHECK-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %ecx ## 4-byte Reload
514514
; CHECK-NEXT: addl %eax, %ecx
515515
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
516-
; CHECK-NEXT: leal 2(%edx), %edx
516+
; CHECK-NEXT: addl $2, %edx
517517
; CHECK-NEXT: movl %edx, {{[-0-9]+}}(%e{{[sb]}}p) ## 4-byte Spill
518518
; CHECK-NEXT: movl {{[-0-9]+}}(%e{{[sb]}}p), %edx ## 4-byte Reload
519519
; CHECK-NEXT: addl %edx, %eax

llvm/test/CodeGen/X86/pr47024.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
3+
4+
define void @_Z4testv() {
5+
; CHECK-LABEL: _Z4testv:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: movabsq $21542142465, %rdi # imm = 0x504030201
8+
; CHECK-NEXT: movabsq $723401749922909195, %rdx # imm = 0xA0A0A0F0E0D0C0B
9+
; CHECK-NEXT: movabsq $723401728380766730, %rcx # imm = 0xA0A0A0A0A0A0A0A
10+
; CHECK-NEXT: movabsq $1446803478303675925, %r8 # imm = 0x1414141918171615
11+
; CHECK-NEXT: movabsq $798285110420182026, %r9 # imm = 0xB1414141414140A
12+
; CHECK-NEXT: xorl %esi, %esi
13+
; CHECK-NEXT: jmp _Z8process36data_tS_S_ # TAILCALL
14+
tail call void @_Z8process36data_tS_S_(i64 21542142465, i64 0, i64 723401749922909195, i64 723401728380766730, i64 1446803478303675925, i64 798285110420182026)
15+
ret void
16+
}
17+
18+
declare void @_Z8process36data_tS_S_(i64, i64, i64, i64, i64, i64)

0 commit comments

Comments
 (0)