Skip to content

Commit b2982a7

Browse files
committed
[PowerPC] Check ResNo at end of BitPermutationSelector::Select32
If it optimizes away a permutation (rotate all 32 bits left by 0), the result might be from a SDNode with more than one result, such as a load <pre-inc> node. The node replacement assumes result number 0. If it isn't 0, kludge by adding an extra node. Fixes #133507
1 parent c8b6ddf commit b2982a7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,11 @@ class BitPermutationSelector {
23372337
ANDIVal, ANDISVal), 0);
23382338
}
23392339

2340+
// Caller assumes ResNo == 0, but we might have ResNo != 0 after
2341+
// optimizing away a permutation. Kludge with an extra node.
2342+
if (Res.getResNo() != 0)
2343+
return CurDAG->getMachineNode(PPC::OR, dl, MVT::i32, Res, Res);
2344+
23402345
return Res.getNode();
23412346
}
23422347

llvm/test/CodeGen/PowerPC/lwzu-i48.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc -mtriple=powerpc-unknown-openbsd < %s | FileCheck %s
2+
3+
; BitPermutationSelector in PPCISelDAGToDAG.cpp was taking the wrong
4+
; result of a load <pre-inc> after optimizing away a permutation.
5+
; Here, the big end of i48 %3 was %1 but should be %0.
6+
7+
define i32 @hop(ptr %out, ptr %in) {
8+
entry:
9+
%0 = getelementptr i8, ptr %in, i32 28
10+
%1 = load i32, ptr %0, align 4
11+
%2 = ptrtoint ptr %0 to i48
12+
%3 = shl i48 %2, 16
13+
store i48 %3, ptr %out, align 4
14+
ret i32 %1
15+
}
16+
; The stw should store POINTER, not VALUE.
17+
; CHECK: lwzu [[VALUE:[0-9]+]], 28([[POINTER:[0-9]+]])
18+
; CHECK: mr [[MOVED:[0-9]+]], [[POINTER]]
19+
; CHECK: stw [[MOVED]], 0({{[0-9]+}})

0 commit comments

Comments
 (0)