Skip to content

Commit 1f3be0e

Browse files
nemanjaitstellar
authored andcommitted
[PowerPC] Do not assume operand of ADDI is an immediate
After pseudo-expansion, we may end up with ADDI (add immediate) instructions where the operand is not an immediate but a relocation. For such instructions, attempts to get the immediate result in assertion failures for obvious reasons. Fixes: https://bugs.llvm.org/show_bug.cgi?id=45432 (cherry picked from commit a56d057)
1 parent f5bad9c commit 1f3be0e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,10 @@ bool PPCInstrInfo::isADDIInstrEligibleForFolding(MachineInstr &ADDIMI,
26312631
if (Opc != PPC::ADDI && Opc != PPC::ADDI8)
26322632
return false;
26332633

2634+
// The operand may not necessarily be an immediate - it could be a relocation.
2635+
if (!ADDIMI.getOperand(2).isImm())
2636+
return false;
2637+
26342638
Imm = ADDIMI.getOperand(2).getImm();
26352639

26362640
return true;

llvm/test/CodeGen/PowerPC/pr45432.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr9 < %s | FileCheck %s
3+
%0 = type { double, [0 x %1] }
4+
%1 = type { i32 }
5+
6+
@f = external dso_local thread_local local_unnamed_addr global %0, align 8
7+
@g = external dso_local local_unnamed_addr global i32, align 4
8+
9+
; Function Attrs: nounwind
10+
define dso_local void @h() local_unnamed_addr #0 {
11+
; CHECK-LABEL: h:
12+
; CHECK: # %bb.0: # %bb
13+
; CHECK-NEXT: mflr 0
14+
; CHECK-NEXT: std 0, 16(1)
15+
; CHECK-NEXT: stdu 1, -64(1)
16+
; CHECK-NEXT: addis 3, 2, g@toc@ha
17+
; CHECK-NEXT: lwz 3, g@toc@l(3)
18+
; CHECK-NEXT: std 30, 48(1) # 8-byte Folded Spill
19+
; CHECK-NEXT: extswsli 30, 3, 2
20+
; CHECK-NEXT: addis 3, 2, f@got@tlsld@ha
21+
; CHECK-NEXT: addi 3, 3, f@got@tlsld@l
22+
; CHECK-NEXT: bl __tls_get_addr(f@tlsld)
23+
; CHECK-NEXT: nop
24+
; CHECK-NEXT: addis 3, 3, f@dtprel@ha
25+
; CHECK-NEXT: addi 3, 3, f@dtprel@l
26+
; CHECK-NEXT: add 3, 3, 30
27+
; CHECK-NEXT: lwz 3, 8(3)
28+
; CHECK-NEXT: cmplwi 3, 0
29+
; CHECK-NEXT: bne- 0, .LBB0_2
30+
; CHECK-NEXT: # %bb.1: # %bb6
31+
; CHECK-NEXT: ld 30, 48(1) # 8-byte Folded Reload
32+
; CHECK-NEXT: addi 1, 1, 64
33+
; CHECK-NEXT: ld 0, 16(1)
34+
; CHECK-NEXT: mtlr 0
35+
; CHECK-NEXT: blr
36+
; CHECK-NEXT: .LBB0_2: # %bb5
37+
bb:
38+
%i = load i32, i32* @g, align 4
39+
%i1 = sext i32 %i to i64
40+
%i2 = getelementptr inbounds [0 x %1], [0 x %1]* bitcast (double* getelementptr inbounds (%0, %0* @f, i64 1, i32 0) to [0 x %1]*), i64 0, i64 %i1, i32 0
41+
%i3 = load i32, i32* %i2, align 4
42+
%i4 = icmp eq i32 %i3, 0
43+
br i1 %i4, label %bb6, label %bb5
44+
45+
bb5: ; preds = %bb
46+
unreachable
47+
48+
bb6: ; preds = %bb
49+
ret void
50+
}
51+
52+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)