Skip to content

Commit 144bdf3

Browse files
committed
[VPlan] Also check if plan for best legacy VF contains simplifications.
The plan for the VF chosen by the legacy cost model could also contain additional simplifications that cause cost differences. Also check if it contains simplifications. Fixes #114860.
1 parent 7dffc96 commit 144bdf3

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7521,6 +7521,8 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
75217521
precomputeCosts(BestPlan, BestFactor.Width, CostCtx);
75227522
assert((BestFactor.Width == LegacyVF.Width ||
75237523
planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width),
7524+
CostCtx, OrigLoop) ||
7525+
planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width),
75247526
CostCtx, OrigLoop)) &&
75257527
" VPlan cost model and legacy cost model disagreed");
75267528
assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) &&
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -p loop-vectorize -S %s | FileCheck %s
3+
4+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
5+
target triple = "riscv64-unknown-linux-gnu"
6+
7+
; Test for https://github.com/llvm/llvm-project/issues/114860.
8+
define void @test_invariant_cond_for_select(ptr %dst, i8 %x) #0 {
9+
; CHECK-LABEL: define void @test_invariant_cond_for_select(
10+
; CHECK-SAME: ptr [[DST:%.*]], i8 [[X:%.*]]) #[[ATTR0:[0-9]+]] {
11+
; CHECK-NEXT: [[ENTRY:.*]]:
12+
; CHECK-NEXT: br label %[[LOOP:.*]]
13+
; CHECK: [[LOOP]]:
14+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
15+
; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8 [[X]], 0
16+
; CHECK-NEXT: [[C_2:%.*]] = icmp sgt i64 [[IV]], 0
17+
; CHECK-NEXT: [[C_2_EXT:%.*]] = zext i1 [[C_2]] to i64
18+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C_1]], i64 [[C_2_EXT]], i64 0
19+
; CHECK-NEXT: [[SEL_TRUNC:%.*]] = trunc i64 [[SEL]] to i8
20+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 [[IV]]
21+
; CHECK-NEXT: store i8 [[SEL_TRUNC]], ptr [[GEP]], align 1
22+
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 4
23+
; CHECK-NEXT: [[EC:%.*]] = icmp ult i64 [[IV]], 14
24+
; CHECK-NEXT: br i1 [[EC]], label %[[LOOP]], label %[[EXIT:.*]]
25+
; CHECK: [[EXIT]]:
26+
; CHECK-NEXT: ret void
27+
;
28+
entry:
29+
br label %loop
30+
31+
loop:
32+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
33+
%c.1 = icmp eq i8 %x, 0
34+
%c.2 = icmp sgt i64 %iv, 0
35+
%c.2.ext = zext i1 %c.2 to i64
36+
%sel = select i1 %c.1, i64 %c.2.ext, i64 0
37+
%sel.trunc = trunc i64 %sel to i8
38+
%gep = getelementptr inbounds i8, ptr %dst, i64 %iv
39+
store i8 %sel.trunc, ptr %gep, align 1
40+
%iv.next = add i64 %iv, 4
41+
%ec = icmp ult i64 %iv, 14
42+
br i1 %ec, label %loop, label %exit
43+
44+
exit:
45+
ret void
46+
}
47+
48+
attributes #0 = { "target-features"="+64bit,+v" }
49+

0 commit comments

Comments
 (0)