Skip to content

Commit 0ef24aa

Browse files
authored
Fix for logic in combineExtract() (#108208)
A (csmith) test case appeared where combineExtract() crashed when the input vector was a bitcast into a vector of i1:s. Fix this by adding a check with canTreatAsByteVector() before the call.
1 parent c71b212 commit 0ef24aa

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7361,8 +7361,9 @@ SDValue SystemZTargetLowering::combineEXTRACT_VECTOR_ELT(
73617361
if (auto *IndexN = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
73627362
SDValue Op0 = N->getOperand(0);
73637363
EVT VecVT = Op0.getValueType();
7364-
return combineExtract(SDLoc(N), N->getValueType(0), VecVT, Op0,
7365-
IndexN->getZExtValue(), DCI, false);
7364+
if (canTreatAsByteVector(VecVT))
7365+
return combineExtract(SDLoc(N), N->getValueType(0), VecVT, Op0,
7366+
IndexN->getZExtValue(), DCI, false);
73667367
}
73677368
return SDValue();
73687369
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -mtriple=s390x-linux-gnu -mcpu=z16 < %s | FileCheck %s
2+
;
3+
; Check that DAGCombiner doesn't crash in SystemZ combineExtract()
4+
; when handling EXTRACT_VECTOR_ELT with a vector of i1:s.
5+
6+
define i32 @fun(i32 %arg) {
7+
; CHECK-LABEL: fun:
8+
entry:
9+
%cc = icmp eq i32 %arg, 0
10+
br label %loop
11+
12+
loop:
13+
%P = phi <128 x i1> [ zeroinitializer, %entry ], [ bitcast (<2 x i64> <i64 3, i64 3> to <128 x i1>), %loop ]
14+
br i1 %cc, label %exit, label %loop
15+
16+
exit:
17+
%E = extractelement <128 x i1> %P, i64 0
18+
%Res = zext i1 %E to i32
19+
ret i32 %Res
20+
}

0 commit comments

Comments
 (0)