Skip to content

Commit 22067a8

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

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
@@ -9470,12 +9470,13 @@ SDValue PPCTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const {
94709470
SDLoc dl(Op);
94719471
SDValue Op0 = Op->getOperand(0);
94729472

9473+
if (!Subtarget.isPPC64() || (Op0.getOpcode() != ISD::BUILD_PAIR) ||
9474+
(Op.getValueType() != MVT::f128))
9475+
return SDValue();
9476+
94739477
SDValue Lo = Op0.getOperand(0);
94749478
SDValue Hi = Op0.getOperand(1);
9475-
9476-
if ((Op.getValueType() != MVT::f128) ||
9477-
(Op0.getOpcode() != ISD::BUILD_PAIR) || (Lo.getValueType() != MVT::i64) ||
9478-
(Hi.getValueType() != MVT::i64) || !Subtarget.isPPC64())
9479+
if ((Lo.getValueType() != MVT::i64) || (Hi.getValueType() != MVT::i64))
94799480
return SDValue();
94809481

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