Skip to content

Commit 810a73b

Browse files
committed
Fix for logic in combineExtract()
1 parent 925b220 commit 810a73b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,13 +6569,12 @@ SDValue SystemZTargetLowering::combineExtract(const SDLoc &DL, EVT ResVT,
65696569
// The number of bytes being extracted.
65706570
unsigned BytesPerElement = VecVT.getVectorElementType().getStoreSize();
65716571

6572-
for (;;) {
6572+
while (canTreatAsByteVector(Op.getValueType())) {
65736573
unsigned Opcode = Op.getOpcode();
65746574
if (Opcode == ISD::BITCAST)
65756575
// Look through bitcasts.
65766576
Op = Op.getOperand(0);
6577-
else if ((Opcode == ISD::VECTOR_SHUFFLE || Opcode == SystemZISD::SPLAT) &&
6578-
canTreatAsByteVector(Op.getValueType())) {
6577+
else if (Opcode == ISD::VECTOR_SHUFFLE || Opcode == SystemZISD::SPLAT) {
65796578
// Get a VPERM-like permute mask and see whether the bytes covered
65806579
// by the extracted element are a contiguous sequence from one
65816580
// source operand.
@@ -6597,8 +6596,7 @@ SDValue SystemZTargetLowering::combineExtract(const SDLoc &DL, EVT ResVT,
65976596
Index = Byte / BytesPerElement;
65986597
Op = Op.getOperand(unsigned(First) / Bytes.size());
65996598
Force = true;
6600-
} else if (Opcode == ISD::BUILD_VECTOR &&
6601-
canTreatAsByteVector(Op.getValueType())) {
6599+
} else if (Opcode == ISD::BUILD_VECTOR) {
66026600
// We can only optimize this case if the BUILD_VECTOR elements are
66036601
// at least as wide as the extracted value.
66046602
EVT OpVT = Op.getValueType();
@@ -6627,7 +6625,6 @@ SDValue SystemZTargetLowering::combineExtract(const SDLoc &DL, EVT ResVT,
66276625
} else if ((Opcode == ISD::SIGN_EXTEND_VECTOR_INREG ||
66286626
Opcode == ISD::ZERO_EXTEND_VECTOR_INREG ||
66296627
Opcode == ISD::ANY_EXTEND_VECTOR_INREG) &&
6630-
canTreatAsByteVector(Op.getValueType()) &&
66316628
canTreatAsByteVector(Op.getOperand(0).getValueType())) {
66326629
// Make sure that only the unextended bits are significant.
66336630
EVT ExtVT = Op.getValueType();
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)