Skip to content

Commit 54e570d

Browse files
committed
[PowerPC] Do not emit XXSPLTI32DX for sub 64-bit constants
If the APInt returned by BuildVectorSDNode::isConstantSplat() is narrower than 64 bits, the result produced by XXSPLTI32DX is incorrect. The result returned by the function appears to be incorrect and we'll investigate/fix it in a follow-up commit. However, since this causes miscompiles, we must temporarily disable emitting this instruction for such values.
1 parent fc2f27c commit 54e570d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8613,7 +8613,8 @@ SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op,
86138613
PPCISD::XXSPLTI_SP_TO_DP, dl, MVT::v2f64,
86148614
DAG.getTargetConstant(APSplatBits.getZExtValue(), dl, MVT::i32));
86158615
return DAG.getBitcast(Op.getValueType(), SplatNode);
8616-
} else { // We may lose precision, so we have to use XXSPLTI32DX.
8616+
} else if (APSplatBits.getBitWidth() == 64) {
8617+
// We may lose precision, so we have to use XXSPLTI32DX.
86178618

86188619
uint32_t Hi =
86198620
(uint32_t)((APSplatBits.getZExtValue() & 0xFFFFFFFF00000000LL) >> 32);

llvm/test/CodeGen/PowerPC/p10-splatImm32.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,25 @@ define dso_local <8 x i16> @test_xxsplti32dx_9() {
100100
entry:
101101
ret <8 x i16> <i16 291, i16 undef, i16 undef, i16 364, i16 undef, i16 1, i16 173, i16 undef>
102102
}
103+
104+
define dso_local <16 x i8> @test_xxsplti32dx_10() {
105+
; CHECK-LABEL: test_xxsplti32dx_10:
106+
; CHECK: # %bb.0: # %entry
107+
; CHECK-NEXT: xxlxor vs34, vs34, vs34
108+
; CHECK-NEXT: xxsplti32dx vs34, 0, 1207959552
109+
; CHECK-NEXT: blr
110+
entry:
111+
ret <16 x i8> <i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 72, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 72>
112+
}
113+
114+
; FIXME: It appears that there is something wrong with the computation
115+
; of the 64-bit constant to splat so we cannot emit xxsplti32dx for
116+
; this test case for now.
117+
define dso_local <16 x i8> @constSplatBug() {
118+
; CHECK-LABEL: constSplatBug:
119+
; CHECK: # %bb.0: # %entry
120+
; CHECK-NEXT: plxv vs34, .LCPI10_0@PCREL(0), 1
121+
; CHECK-NEXT: blr
122+
entry:
123+
ret <16 x i8> <i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 71, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 71>
124+
}

0 commit comments

Comments
 (0)