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) 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