Skip to content

Commit e116cec

Browse files
committed
Fix for logic in combineExtract()
1 parent 85220a0 commit e116cec

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
@@ -6586,13 +6586,12 @@ SDValue SystemZTargetLowering::combineExtract(const SDLoc &DL, EVT ResVT,
65866586
// The number of bytes being extracted.
65876587
unsigned BytesPerElement = VecVT.getVectorElementType().getStoreSize();
65886588

6589-
for (;;) {
6589+
while (canTreatAsByteVector(Op.getValueType())) {
65906590
unsigned Opcode = Op.getOpcode();
65916591
if (Opcode == ISD::BITCAST)
65926592
// Look through bitcasts.
65936593
Op = Op.getOperand(0);
6594-
else if ((Opcode == ISD::VECTOR_SHUFFLE || Opcode == SystemZISD::SPLAT) &&
6595-
canTreatAsByteVector(Op.getValueType())) {
6594+
else if (Opcode == ISD::VECTOR_SHUFFLE || Opcode == SystemZISD::SPLAT) {
65966595
// Get a VPERM-like permute mask and see whether the bytes covered
65976596
// by the extracted element are a contiguous sequence from one
65986597
// source operand.
@@ -6614,8 +6613,7 @@ SDValue SystemZTargetLowering::combineExtract(const SDLoc &DL, EVT ResVT,
66146613
Index = Byte / BytesPerElement;
66156614
Op = Op.getOperand(unsigned(First) / Bytes.size());
66166615
Force = true;
6617-
} else if (Opcode == ISD::BUILD_VECTOR &&
6618-
canTreatAsByteVector(Op.getValueType())) {
6616+
} else if (Opcode == ISD::BUILD_VECTOR) {
66196617
// We can only optimize this case if the BUILD_VECTOR elements are
66206618
// at least as wide as the extracted value.
66216619
EVT OpVT = Op.getValueType();
@@ -6644,7 +6642,6 @@ SDValue SystemZTargetLowering::combineExtract(const SDLoc &DL, EVT ResVT,
66446642
} else if ((Opcode == ISD::SIGN_EXTEND_VECTOR_INREG ||
66456643
Opcode == ISD::ZERO_EXTEND_VECTOR_INREG ||
66466644
Opcode == ISD::ANY_EXTEND_VECTOR_INREG) &&
6647-
canTreatAsByteVector(Op.getValueType()) &&
66486645
canTreatAsByteVector(Op.getOperand(0).getValueType())) {
66496646
// Make sure that only the unextended bits are significant.
66506647
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)