Skip to content

[PowerPC] Check ResNo at end of BitPermutationSelector::Select32 #151429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,11 @@ class BitPermutationSelector {
ANDIVal, ANDISVal), 0);
}

// Caller assumes ResNo == 0, but we might have ResNo != 0 after
// optimizing away a permutation. Kludge with an extra node.
if (Res.getResNo() != 0)
return CurDAG->getMachineNode(PPC::OR, dl, MVT::i32, Res, Res);

return Res.getNode();
}

Expand Down
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/PowerPC/lwzu-i48.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; RUN: llc -mtriple=powerpc-unknown-openbsd < %s | FileCheck %s

; BitPermutationSelector in PPCISelDAGToDAG.cpp was taking the wrong
; result of a load <pre-inc> after optimizing away a permutation.
; Here, the big end of i48 %3 was %1 but should be %0.

define i32 @hop(ptr %out, ptr %in) {
entry:
%0 = getelementptr i8, ptr %in, i32 28
%1 = load i32, ptr %0, align 4
%2 = ptrtoint ptr %0 to i48
%3 = shl i48 %2, 16
store i48 %3, ptr %out, align 4
ret i32 %1
}
; The stw should store POINTER, not VALUE.
; CHECK: lwzu [[VALUE:[0-9]+]], 28([[POINTER:[0-9]+]])
; CHECK: mr [[MOVED:[0-9]+]], [[POINTER]]
; CHECK: stw [[MOVED]], 0({{[0-9]+}})