Skip to content

Commit ca7d9da

Browse files
syzaarallvmbot
authored andcommitted
[PowerPC] Fix assert exposed by PR 95931 in LowerBITCAST (llvm#108062)
Hit Assertion failed: Num < NumOperands && "Invalid child # of SDNode!" Fix by checking opcode and value type before calling getOperand. (cherry picked from commit 22067a8)
1 parent f0010d1 commit ca7d9da

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -9338,12 +9338,13 @@ SDValue PPCTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const {
93389338
SDLoc dl(Op);
93399339
SDValue Op0 = Op->getOperand(0);
93409340

9341+
if (!Subtarget.isPPC64() || (Op0.getOpcode() != ISD::BUILD_PAIR) ||
9342+
(Op.getValueType() != MVT::f128))
9343+
return SDValue();
9344+
93419345
SDValue Lo = Op0.getOperand(0);
93429346
SDValue Hi = Op0.getOperand(1);
9343-
9344-
if ((Op.getValueType() != MVT::f128) ||
9345-
(Op0.getOpcode() != ISD::BUILD_PAIR) || (Lo.getValueType() != MVT::i64) ||
9346-
(Hi.getValueType() != MVT::i64) || !Subtarget.isPPC64())
9347+
if ((Lo.getValueType() != MVT::i64) || (Hi.getValueType() != MVT::i64))
93479348
return SDValue();
93489349

93499350
if (!Subtarget.isLittleEndian())

llvm/test/CodeGen/PowerPC/f128-bitcast.ll

+22
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,25 @@ entry:
8686
ret i64 %1
8787
}
8888

89+
define <4 x i32> @truncBitcast(i512 %a) {
90+
; CHECK-LABEL: truncBitcast:
91+
; CHECK: # %bb.0: # %entry
92+
; CHECK-NEXT: mtvsrdd v2, r4, r3
93+
; CHECK-NEXT: blr
94+
;
95+
; CHECK-BE-LABEL: truncBitcast:
96+
; CHECK-BE: # %bb.0: # %entry
97+
; CHECK-BE-NEXT: mtvsrdd v2, r9, r10
98+
; CHECK-BE-NEXT: blr
99+
;
100+
; CHECK-P8-LABEL: truncBitcast:
101+
; CHECK-P8: # %bb.0: # %entry
102+
; CHECK-P8-NEXT: mtfprd f0, r3
103+
; CHECK-P8-NEXT: mtfprd f1, r4
104+
; CHECK-P8-NEXT: xxmrghd v2, vs1, vs0
105+
; CHECK-P8-NEXT: blr
106+
entry:
107+
%0 = trunc i512 %a to i128
108+
%1 = bitcast i128 %0 to <4 x i32>
109+
ret <4 x i32> %1
110+
}

0 commit comments

Comments
 (0)