Skip to content

Commit cf9304d

Browse files
toppercalexcrichton
authored andcommittedNov 11, 2019
convertToThreeAddress, make sure second operand of SUB32ri is really an immediate before calling getImm().
It might be a symbol instead. We can't fold those since we can't negate them. Similar for other SUB with immediates. Fixes PR43529. llvm-svn: 373397
1 parent 14a3b12 commit cf9304d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
 

Diff for: ‎llvm/lib/Target/X86/X86InstrInfo.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ X86InstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
10851085
return nullptr;
10861086
case X86::SUB32ri8:
10871087
case X86::SUB32ri: {
1088+
if (!MI.getOperand(2).isImm())
1089+
return nullptr;
10881090
int64_t Imm = MI.getOperand(2).getImm();
10891091
if (!isInt<32>(-Imm))
10901092
return nullptr;
@@ -1111,6 +1113,8 @@ X86InstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
11111113

11121114
case X86::SUB64ri8:
11131115
case X86::SUB64ri32: {
1116+
if (!MI.getOperand(2).isImm())
1117+
return nullptr;
11141118
int64_t Imm = MI.getOperand(2).getImm();
11151119
if (!isInt<32>(-Imm))
11161120
return nullptr;

Diff for: ‎llvm/test/CodeGen/X86/pr43529.ll

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu | FileCheck %s
3+
4+
define i32 @a() nounwind {
5+
; CHECK-LABEL: a:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: pushl %esi
8+
; CHECK-NEXT: subl $8, %esp
9+
; CHECK-NEXT: leal {{[0-9]+}}(%esp), %esi
10+
; CHECK-NEXT: movl %esi, %eax
11+
; CHECK-NEXT: subl $a, %eax
12+
; CHECK-NEXT: calll d
13+
; CHECK-NEXT: cmpl $a, %esi
14+
; CHECK-NEXT: jbe .LBB0_2
15+
; CHECK-NEXT: .p2align 4, 0x90
16+
; CHECK-NEXT: .LBB0_1: # %for.cond
17+
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
18+
; CHECK-NEXT: jmp .LBB0_1
19+
; CHECK-NEXT: .LBB0_2: # %for.end.split
20+
; CHECK-NEXT: addl $8, %esp
21+
; CHECK-NEXT: popl %esi
22+
; CHECK-NEXT: retl
23+
entry:
24+
%b = alloca i32, align 4
25+
%0 = bitcast i32* %b to i8*
26+
%1 = ptrtoint i32* %b to i32
27+
%sub = sub nsw i32 %1, ptrtoint (i32 ()* @a to i32)
28+
%call = call i32 bitcast (i32 (...)* @d to i32 (i32)*)(i32 inreg %sub)
29+
%cmp = icmp ugt i32* %b, bitcast (i32 ()* @a to i32*)
30+
br i1 %cmp, label %for.cond, label %for.end.split
31+
32+
for.cond: ; preds = %entry, %for.cond
33+
br label %for.cond
34+
35+
for.end.split: ; preds = %entry
36+
ret i32 undef
37+
}
38+
39+
declare i32 @d(...)

0 commit comments

Comments
 (0)
Please sign in to comment.