Skip to content

Commit 7f88177

Browse files
committed
[DAGCombiner] Fix issue llvm#121372
PR llvm#118823 added a DAG combine for extracting elements of a vector returned from SETCC, however it doesn't correctly deal with the case where the vector element type is not i1. In this case we have to take account of the boolean contents, which are represent differently between vectors and scalars. For now, I've just restricted the optimisation to i1 types. Fixes llvm#121372
1 parent 15b8b7e commit 7f88177

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22809,7 +22809,8 @@ static SDValue scalarizeExtractedBinOp(SDNode *ExtElt, SelectionDAG &DAG,
2280922809

2281022810
EVT ResVT = ExtElt->getValueType(0);
2281122811
if (Opc == ISD::SETCC &&
22812-
(ResVT != Vec.getValueType().getVectorElementType() || LegalTypes))
22812+
(ResVT != Vec.getValueType().getVectorElementType() || ResVT != MVT::i1 ||
22813+
LegalTypes))
2281322814
return SDValue();
2281422815

2281522816
// Targets may want to avoid this to prevent an expensive register transfer.

llvm/test/CodeGen/AArch64/extract-vector-cmp.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ define i128 @extract_icmp_v1i128(ptr %p) {
5858
; CHECK-LABEL: extract_icmp_v1i128:
5959
; CHECK: // %bb.0:
6060
; CHECK-NEXT: ldp x9, x8, [x0]
61-
; CHECK-NEXT: mov x1, xzr
6261
; CHECK-NEXT: orr x8, x9, x8
6362
; CHECK-NEXT: cmp x8, #0
64-
; CHECK-NEXT: cset w0, eq
63+
; CHECK-NEXT: cset w8, eq
64+
; CHECK-NEXT: sbfx x0, x8, #0, #1
65+
; CHECK-NEXT: mov x1, x0
6566
; CHECK-NEXT: ret
6667
%load = load <1 x i128>, ptr %p, align 16
6768
%cmp = icmp eq <1 x i128> %load, zeroinitializer
@@ -144,9 +145,9 @@ for.cond.cleanup:
144145
define i32 @issue_121372(<4 x i32> %0) {
145146
; CHECK-LABEL: issue_121372:
146147
; CHECK: // %bb.0:
148+
; CHECK-NEXT: movi v1.2d, #0000000000000000
149+
; CHECK-NEXT: cmhs v0.4s, v1.4s, v0.4s
147150
; CHECK-NEXT: fmov w8, s0
148-
; CHECK-NEXT: cmp w8, #0
149-
; CHECK-NEXT: cset w8, eq
150151
; CHECK-NEXT: cmp w8, #1
151152
; CHECK-NEXT: csetm w0, lt
152153
; CHECK-NEXT: ret

0 commit comments

Comments
 (0)