[PATCH] D30362: [PPC] Fix code generation for bswap(int32) followed by store16
Guozhi Wei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 13:20:04 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296811: [PPC] Fix code generation for bswap(int32) followed by store16 (authored by Carrot).
Changed prior to commit:
https://reviews.llvm.org/D30362?vs=89743&id=90381#toc
Repository:
rL LLVM
https://reviews.llvm.org/D30362
Files:
llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/trunk/test/CodeGen/PowerPC/pr32063.ll
Index: llvm/trunk/test/CodeGen/PowerPC/pr32063.ll
===================================================================
--- llvm/trunk/test/CodeGen/PowerPC/pr32063.ll
+++ llvm/trunk/test/CodeGen/PowerPC/pr32063.ll
@@ -0,0 +1,16 @@
+; RUN: llc -O2 < %s | FileCheck %s
+target triple = "powerpc64le-linux-gnu"
+
+define void @foo(i32 %v, i16* %p) {
+ %1 = and i32 %v, -65536
+ %2 = tail call i32 @llvm.bswap.i32(i32 %1)
+ %conv = trunc i32 %2 to i16
+ store i16 %conv, i16* %p
+ ret void
+
+; CHECK: srwi
+; CHECK: sthbrx
+; CHECK-NOT: stwbrx
+}
+
+declare i32 @llvm.bswap.i32(i32)
Index: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
===================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -11391,9 +11391,17 @@
if (BSwapOp.getValueType() == MVT::i16)
BSwapOp = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, BSwapOp);
+ // If the type of BSWAP operand is wider than stored memory width
+ // it need to be shifted to the right side before STBRX.
+ EVT mVT = cast<StoreSDNode>(N)->getMemoryVT();
+ if (Op1VT.bitsGT(mVT)) {
+ int shift = Op1VT.getSizeInBits() - mVT.getSizeInBits();
+ BSwapOp = DAG.getNode(ISD::SRL, dl, Op1VT, BSwapOp,
+ DAG.getConstant(shift, dl, MVT::i32));
+ }
+
SDValue Ops[] = {
- N->getOperand(0), BSwapOp, N->getOperand(2),
- DAG.getValueType(N->getOperand(1).getValueType())
+ N->getOperand(0), BSwapOp, N->getOperand(2), DAG.getValueType(mVT)
};
return
DAG.getMemIntrinsicNode(PPCISD::STBRX, dl, DAG.getVTList(MVT::Other),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30362.90381.patch
Type: text/x-patch
Size: 1748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/2d963255/attachment.bin>
More information about the llvm-commits
mailing list