Skip to content

Commit 9fa366d

Browse files
committed
Merging r327651:
------------------------------------------------------------------------ r327651 | carrot | 2018-03-15 10:49:12 -0700 (Thu, 15 Mar 2018) | 9 lines [PPC] Avoid non-simple MVT in STBRX optimization PR35402 triggered this case. It bswap and stores a 48bit value, current STBRX optimization transforms it into STBRX. Unfortunately 48bit is not a simple MVT, there is no PPC instruction to support it, and it can't be automatically expanded by llvm, so caused a crash. This patch detects the non-simple MVT and returns early. Differential Revision: https://reviews.llvm.org/D44500 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@329641 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7e48926 commit 9fa366d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12264,14 +12264,18 @@ SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N,
1226412264
N->getOperand(1).getValueType() == MVT::i16 ||
1226512265
(Subtarget.hasLDBRX() && Subtarget.isPPC64() &&
1226612266
N->getOperand(1).getValueType() == MVT::i64))) {
12267+
// STBRX can only handle simple types.
12268+
EVT mVT = cast<StoreSDNode>(N)->getMemoryVT();
12269+
if (mVT.isExtended())
12270+
break;
12271+
1226712272
SDValue BSwapOp = N->getOperand(1).getOperand(0);
1226812273
// Do an any-extend to 32-bits if this is a half-word input.
1226912274
if (BSwapOp.getValueType() == MVT::i16)
1227012275
BSwapOp = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, BSwapOp);
1227112276

1227212277
// If the type of BSWAP operand is wider than stored memory width
1227312278
// it need to be shifted to the right side before STBRX.
12274-
EVT mVT = cast<StoreSDNode>(N)->getMemoryVT();
1227512279
if (Op1VT.bitsGT(mVT)) {
1227612280
int Shift = Op1VT.getSizeInBits() - mVT.getSizeInBits();
1227712281
BSwapOp = DAG.getNode(ISD::SRL, dl, Op1VT, BSwapOp,

test/CodeGen/PowerPC/pr35402.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llc -O2 < %s | FileCheck %s
2+
target triple = "powerpc64le-linux-gnu"
3+
4+
define void @test(i8* %p, i64 %data) {
5+
entry:
6+
%0 = tail call i64 @llvm.bswap.i64(i64 %data)
7+
%ptr = bitcast i8* %p to i48*
8+
%val = trunc i64 %0 to i48
9+
store i48 %val, i48* %ptr, align 1
10+
ret void
11+
12+
; CHECK: sth
13+
; CHECK: stw
14+
; CHECK-NOT: stdbrx
15+
16+
}
17+
18+
declare i64 @llvm.bswap.i64(i64)

0 commit comments

Comments
 (0)