Skip to content

Commit 52ac914

Browse files
nemanjaitstellar
authored andcommitted
[PowerPC] Fix crash in peephole optimization
When converting reg+reg shifts to reg+imm rotates, we neglect to consider the CodeGenOnly versions of the 32-bit shift mnemonics. This means we produce a rotate with missing operands which causes a crash. Committing this fix without review since it is non-controversial that the list of mnemonics to consider should include the 64-bit aliases for the exact mnemonics. Fixes PR44183. (cherry picked from commit 241cbf2)
1 parent ed3f33f commit 52ac914

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,8 +3529,10 @@ bool PPCInstrInfo::transformToImmFormFedByLI(MachineInstr &MI,
35293529
ForwardKilledOperandReg = MI.getOperand(ConstantOpNo).getReg();
35303530

35313531
unsigned Opc = MI.getOpcode();
3532-
bool SpecialShift32 =
3533-
Opc == PPC::SLW || Opc == PPC::SLWo || Opc == PPC::SRW || Opc == PPC::SRWo;
3532+
bool SpecialShift32 = Opc == PPC::SLW || Opc == PPC::SLWo ||
3533+
Opc == PPC::SRW || Opc == PPC::SRWo ||
3534+
Opc == PPC::SLW8 || Opc == PPC::SLW8o ||
3535+
Opc == PPC::SRW8 || Opc == PPC::SRW8o;
35343536
bool SpecialShift64 =
35353537
Opc == PPC::SLD || Opc == PPC::SLDo || Opc == PPC::SRD || Opc == PPC::SRDo;
35363538
bool SetCR = Opc == PPC::SLWo || Opc == PPC::SRWo ||

llvm/test/CodeGen/PowerPC/pr44183.ll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
3+
; RUN: -ppc-asm-full-reg-names -mcpu=pwr8 < %s | FileCheck %s
4+
%struct.m.2.5.8.11 = type { %struct.l.0.3.6.9, [7 x i8], %struct.a.1.4.7.10 }
5+
%struct.l.0.3.6.9 = type { i8 }
6+
%struct.a.1.4.7.10 = type { [27 x i8], [0 x i32], [4 x i8] }
7+
define void @_ZN1m1nEv(%struct.m.2.5.8.11* %this) local_unnamed_addr nounwind align 2 {
8+
; CHECK-LABEL: _ZN1m1nEv:
9+
; CHECK: # %bb.0: # %entry
10+
; CHECK-NEXT: mflr r0
11+
; CHECK-NEXT: std r30, -16(r1) # 8-byte Folded Spill
12+
; CHECK-NEXT: std r0, 16(r1)
13+
; CHECK-NEXT: stdu r1, -48(r1)
14+
; CHECK-NEXT: mr r30, r3
15+
; CHECK-NEXT: ld r4, 8(r30)
16+
; CHECK-NEXT: lwz r5, 36(r30)
17+
; CHECK-NEXT: rldicl r4, r4, 60, 4
18+
; CHECK-NEXT: rlwinm r3, r4, 31, 0, 0
19+
; CHECK-NEXT: rlwinm r4, r5, 0, 31, 31
20+
; CHECK-NEXT: or r4, r4, r3
21+
; CHECK-NEXT: bl _ZN1llsE1d
22+
; CHECK-NEXT: nop
23+
; CHECK-NEXT: ld r3, 16(r30)
24+
; CHECK-NEXT: ld r4, 8(r30)
25+
; CHECK-NEXT: rldicl r4, r4, 60, 4
26+
; CHECK-NEXT: sldi r3, r3, 60
27+
; CHECK-NEXT: or r3, r4, r3
28+
; CHECK-NEXT: sldi r3, r3, 31
29+
; CHECK-NEXT: clrldi r4, r3, 32
30+
; CHECK-NEXT: bl _ZN1llsE1d
31+
; CHECK-NEXT: nop
32+
; CHECK-NEXT: addi r1, r1, 48
33+
; CHECK-NEXT: ld r0, 16(r1)
34+
; CHECK-NEXT: mtlr r0
35+
; CHECK-NEXT: ld r30, -16(r1) # 8-byte Folded Reload
36+
; CHECK-NEXT: blr
37+
entry:
38+
%bc = getelementptr inbounds %struct.m.2.5.8.11, %struct.m.2.5.8.11* %this, i64 0, i32 2
39+
%0 = bitcast %struct.a.1.4.7.10* %bc to i216*
40+
%bf.load = load i216, i216* %0, align 8
41+
%bf.lshr = lshr i216 %bf.load, 4
42+
%shl.i23 = shl i216 %bf.lshr, 31
43+
%shl.i = trunc i216 %shl.i23 to i32
44+
%arrayidx = getelementptr inbounds %struct.m.2.5.8.11, %struct.m.2.5.8.11* %this, i64 0, i32 2, i32 1, i64 0
45+
%1 = load i32, i32* %arrayidx, align 4
46+
%and.i = and i32 %1, 1
47+
%or.i = or i32 %and.i, %shl.i
48+
tail call void @_ZN1llsE1d(%struct.l.0.3.6.9* undef, i32 %or.i) #1
49+
%bf.load10 = load i216, i216* %0, align 8
50+
%bf.lshr11 = lshr i216 %bf.load10, 4
51+
%shl.i1524 = shl i216 %bf.lshr11, 31
52+
%shl.i15 = trunc i216 %shl.i1524 to i32
53+
tail call void @_ZN1llsE1d(%struct.l.0.3.6.9* undef, i32 %shl.i15) #1
54+
ret void
55+
}
56+
declare void @_ZN1llsE1d(%struct.l.0.3.6.9*, i32) local_unnamed_addr #0

0 commit comments

Comments
 (0)