[PATCH] D16687: Fix for PR26356
Nemanja Ivanovic via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 28 10:30:39 PST 2016
nemanjai created this revision.
nemanjai added reviewers: kbarton, hfinkel.
nemanjai added a subscriber: llvm-commits.
nemanjai set the repository for this revision to rL LLVM.
Herald added a subscriber: MatzeB.
Fast Isel fails when trying to load an unsigned immediate greater than 0x7FFF. The li instruction takes a signed immediate so it isn't appropriate for such values.
Repository:
rL LLVM
http://reviews.llvm.org/D16687
Files:
lib/Target/PowerPC/PPCFastISel.cpp
test/CodeGen/PowerPC/pr26356.ll
Index: test/CodeGen/PowerPC/pr26356.ll
===================================================================
--- test/CodeGen/PowerPC/pr26356.ll
+++ test/CodeGen/PowerPC/pr26356.ll
@@ -0,0 +1,10 @@
+; RUN: llc -mcpu=pwr7 -mtriple=powerpc64le-unknown-unknown -O0 < %s | FileCheck %s
+
+; Function Attrs: nounwind
+define internal zeroext i16 @zot() #0 {
+ ret i16 32768
+}
+
+; CHECK: li 3, 0
+; CHECK: ori 3, 3, 32768
+; CHECK: blr
Index: lib/Target/PowerPC/PPCFastISel.cpp
===================================================================
--- lib/Target/PowerPC/PPCFastISel.cpp
+++ lib/Target/PowerPC/PPCFastISel.cpp
@@ -2100,6 +2100,19 @@
.addImm(CI->getSExtValue());
return ImmReg;
} else if (!UseSExt && isUInt<16>(CI->getZExtValue())) {
+ // The li instruction loads signed 16-bit immediates so we
+ // need an extra step for unsigned values with the high bit set.
+ if (CI->getZExtValue() > 0x7FFF) {
+ unsigned LdImm = (VT == MVT::i64) ? PPC::LI8 : PPC::LI;
+ unsigned OrImm = (VT == MVT::i64) ? PPC::ORI8 : PPC::ORI;
+ unsigned ResReg = createResultReg(RC);
+ unsigned TmpReg = createResultReg(RC);
+ BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(LdImm), TmpReg)
+ .addImm(0);
+ BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(OrImm), ResReg)
+ .addReg(TmpReg).addImm(CI->getZExtValue());
+ return ResReg;
+ }
unsigned Opc = (VT == MVT::i64) ? PPC::LI8 : PPC::LI;
unsigned ImmReg = createResultReg(RC);
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ImmReg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16687.46294.patch
Type: text/x-patch
Size: 1603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160128/b71ee0c6/attachment.bin>
More information about the llvm-commits
mailing list