Skip to content

Commit 59cb55d

Browse files
authored
VPlan: add missing case for LogicalAnd; fix crash (#93553)
VPTypeAnalysis::inferScalarTypeForRecipe is missing the case for VPInstruction::LogicalAnd, due to which the test vplan-incomplete-cases.ll crashes. Add this missing case, and move the test in vplan-infer-not-or-type.ll to vplan-incomplete-cases.ll, showing correct codegen for trip-counts 2 and 3.
1 parent 34b4112 commit 59cb55d

File tree

3 files changed

+120
-64
lines changed

3 files changed

+120
-64
lines changed

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
5757
"unexpected scalar type inferred for operand");
5858
return ResTy;
5959
}
60+
case VPInstruction::LogicalAnd:
61+
return IntegerType::get(Ctx, 1);
6062
case VPInstruction::PtrAdd:
6163
// Return the type based on the pointer argument (i.e. first operand).
6264
return inferScalarType(R->getOperand(0));
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=loop-vectorize -S %s | FileCheck %s
3+
4+
; This test used to crash due to missing Or/Not cases in inferScalarTypeForRecipe.
5+
define void @vplan_incomplete_cases_tc2(i8 %x, i8 %y) {
6+
; CHECK-LABEL: define void @vplan_incomplete_cases_tc2(
7+
; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) {
8+
; CHECK-NEXT: [[ENTRY:.*]]:
9+
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
10+
; CHECK: [[VECTOR_PH]]:
11+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
12+
; CHECK: [[VECTOR_BODY]]:
13+
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
14+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
15+
; CHECK-NEXT: br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
16+
; CHECK: [[MIDDLE_BLOCK]]:
17+
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
18+
; CHECK: [[SCALAR_PH]]:
19+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i8 [ 2, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
20+
; CHECK-NEXT: br label %[[LOOP_HEADER:.*]]
21+
; CHECK: [[LOOP_HEADER]]:
22+
; CHECK-NEXT: [[IV:%.*]] = phi i8 [ [[IV_NEXT:%.*]], %[[LATCH:.*]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ]
23+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y]]
24+
; CHECK-NEXT: [[EXTRACT_T:%.*]] = trunc i8 [[AND]] to i1
25+
; CHECK-NEXT: br i1 [[EXTRACT_T]], label %[[LATCH]], label %[[INDIRECT_LATCH:.*]]
26+
; CHECK: [[INDIRECT_LATCH]]:
27+
; CHECK-NEXT: br label %[[LATCH]]
28+
; CHECK: [[LATCH]]:
29+
; CHECK-NEXT: [[IV_NEXT]] = add i8 [[IV]], 1
30+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[IV]] to i32
31+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[ZEXT]], 1
32+
; CHECK-NEXT: br i1 [[CMP]], label %[[LOOP_HEADER]], label %[[EXIT]], !llvm.loop [[LOOP3:![0-9]+]]
33+
; CHECK: [[EXIT]]:
34+
; CHECK-NEXT: ret void
35+
;
36+
entry:
37+
br label %loop.header
38+
39+
loop.header: ; preds = %latch, %entry
40+
%iv = phi i8 [ %iv.next, %latch ], [ 0, %entry ]
41+
%and = and i8 %x, %y
42+
%extract.t = trunc i8 %and to i1
43+
br i1 %extract.t, label %latch, label %indirect.latch
44+
45+
indirect.latch: ; preds = %loop.header
46+
br label %latch
47+
48+
latch: ; preds = %indirect.latch, loop.header
49+
%iv.next = add i8 %iv, 1
50+
%zext = zext i8 %iv to i32
51+
%cmp = icmp ult i32 %zext, 1
52+
br i1 %cmp, label %loop.header, label %exit
53+
54+
exit: ; preds = %latch
55+
ret void
56+
}
57+
58+
; This test used to crash due to missing the LogicalAnd case in inferScalarTypeForRecipe.
59+
define void @vplan_incomplete_cases_tc3(i8 %x, i8 %y) {
60+
; CHECK-LABEL: define void @vplan_incomplete_cases_tc3(
61+
; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) {
62+
; CHECK-NEXT: [[ENTRY:.*]]:
63+
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
64+
; CHECK: [[VECTOR_PH]]:
65+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
66+
; CHECK: [[VECTOR_BODY]]:
67+
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
68+
; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4
69+
; CHECK-NEXT: br i1 true, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
70+
; CHECK: [[MIDDLE_BLOCK]]:
71+
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
72+
; CHECK: [[SCALAR_PH]]:
73+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i8 [ 4, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
74+
; CHECK-NEXT: br label %[[LOOP_HEADER:.*]]
75+
; CHECK: [[LOOP_HEADER]]:
76+
; CHECK-NEXT: [[IV:%.*]] = phi i8 [ [[IV_NEXT:%.*]], %[[LATCH:.*]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ]
77+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], [[Y]]
78+
; CHECK-NEXT: [[EXTRACT_T:%.*]] = trunc i8 [[AND]] to i1
79+
; CHECK-NEXT: br i1 [[EXTRACT_T]], label %[[LATCH]], label %[[INDIRECT_LATCH:.*]]
80+
; CHECK: [[INDIRECT_LATCH]]:
81+
; CHECK-NEXT: br label %[[LATCH]]
82+
; CHECK: [[LATCH]]:
83+
; CHECK-NEXT: [[IV_NEXT]] = add i8 [[IV]], 1
84+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[IV]] to i32
85+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[ZEXT]], 2
86+
; CHECK-NEXT: br i1 [[CMP]], label %[[LOOP_HEADER]], label %[[EXIT]], !llvm.loop [[LOOP5:![0-9]+]]
87+
; CHECK: [[EXIT]]:
88+
; CHECK-NEXT: ret void
89+
;
90+
entry:
91+
br label %loop.header
92+
93+
loop.header: ; preds = %latch, %entry
94+
%iv = phi i8 [ %iv.next, %latch ], [ 0, %entry ]
95+
%and = and i8 %x, %y
96+
%extract.t = trunc i8 %and to i1
97+
br i1 %extract.t, label %latch, label %indirect.latch
98+
99+
indirect.latch: ; preds = %loop.header
100+
br label %latch
101+
102+
latch: ; preds = %indirect.latch, loop.header
103+
%iv.next = add i8 %iv, 1
104+
%zext = zext i8 %iv to i32
105+
%cmp = icmp ult i32 %zext, 2
106+
br i1 %cmp, label %loop.header, label %exit
107+
108+
exit: ; preds = %latch
109+
ret void
110+
}
111+
;.
112+
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
113+
; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
114+
; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
115+
; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META2]], [[META1]]}
116+
; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]], [[META2]]}
117+
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META2]], [[META1]]}
118+
;.

llvm/test/Transforms/LoopVectorize/vplan-infer-not-or-type.ll

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)