[llvm] Reapply "[VPlan] Remove legacy costing inside VPBlendRecipe::computeCost (#171846)" (PR #172261)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 15 01:02:20 PST 2025
================
@@ -458,11 +458,117 @@ loop.latch:
exit:
ret void
}
+
+; Test case for
+; https://github.com/llvm/llvm-project/pull/171846#issuecomment-3647640019
+define void @only_first_lane_used(i1 %c, ptr %p) #0 {
+; CHECK-LABEL: define void @only_first_lane_used(
+; CHECK-SAME: i1 [[C:%.*]], ptr [[P:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i64 [[TMP0]], 3
+; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
+; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
+; CHECK: [[VECTOR_PH]]:
+; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP3:%.*]] = mul nuw i64 [[TMP2]], 8
+; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
+; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
+; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
+; CHECK: [[VECTOR_BODY]]:
+; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], -1
+; CHECK-NEXT: [[TMP5:%.*]] = getelementptr double, ptr [[P]], i64 [[TMP4]]
+; CHECK-NEXT: [[TMP6:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP7:%.*]] = shl nuw i64 [[TMP6]], 1
+; CHECK-NEXT: [[TMP8:%.*]] = getelementptr double, ptr [[TMP5]], i64 [[TMP7]]
+; CHECK-NEXT: [[TMP9:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP10:%.*]] = shl nuw i64 [[TMP9]], 2
+; CHECK-NEXT: [[TMP11:%.*]] = getelementptr double, ptr [[TMP5]], i64 [[TMP10]]
+; CHECK-NEXT: [[TMP12:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT: [[TMP13:%.*]] = mul nuw i64 [[TMP12]], 6
+; CHECK-NEXT: [[TMP14:%.*]] = getelementptr double, ptr [[TMP5]], i64 [[TMP13]]
+; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x double>, ptr [[TMP5]], align 8
+; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <vscale x 2 x double>, ptr [[TMP8]], align 8
+; CHECK-NEXT: [[WIDE_LOAD2:%.*]] = load <vscale x 2 x double>, ptr [[TMP11]], align 8
+; CHECK-NEXT: [[WIDE_LOAD3:%.*]] = load <vscale x 2 x double>, ptr [[TMP14]], align 8
+; CHECK-NEXT: [[TMP15:%.*]] = fadd <vscale x 2 x double> [[WIDE_LOAD]], splat (double 1.000000e+00)
+; CHECK-NEXT: [[TMP16:%.*]] = fadd <vscale x 2 x double> [[WIDE_LOAD1]], splat (double 1.000000e+00)
+; CHECK-NEXT: [[TMP17:%.*]] = fadd <vscale x 2 x double> [[WIDE_LOAD2]], splat (double 1.000000e+00)
+; CHECK-NEXT: [[TMP18:%.*]] = fadd <vscale x 2 x double> [[WIDE_LOAD3]], splat (double 1.000000e+00)
+; CHECK-NEXT: store <vscale x 2 x double> [[TMP15]], ptr [[TMP5]], align 8
+; CHECK-NEXT: store <vscale x 2 x double> [[TMP16]], ptr [[TMP8]], align 8
+; CHECK-NEXT: store <vscale x 2 x double> [[TMP17]], ptr [[TMP11]], align 8
+; CHECK-NEXT: store <vscale x 2 x double> [[TMP18]], ptr [[TMP14]], align 8
+; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP3]]
+; CHECK-NEXT: [[TMP19:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
+; CHECK-NEXT: br i1 [[TMP19]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
+; CHECK: [[MIDDLE_BLOCK]]:
+; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
+; CHECK-NEXT: br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]]
+; CHECK: [[SCALAR_PH]]:
+; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LATCH:.*]] ]
+; CHECK-NEXT: br i1 [[C]], label %[[BAR:.*]], label %[[FOO:.*]]
+; CHECK: [[FOO]]:
+; CHECK-NEXT: [[FOO_RES:%.*]] = add i64 [[IV]], -1
+; CHECK-NEXT: br label %[[LATCH]]
+; CHECK: [[BAR]]:
+; CHECK-NEXT: [[BAR_RES:%.*]] = add i64 [[IV]], -1
+; CHECK-NEXT: br label %[[LATCH]]
+; CHECK: [[LATCH]]:
+; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ [[FOO_RES]], %[[FOO]] ], [ [[BAR_RES]], %[[BAR]] ]
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr double, ptr [[P]], i64 [[PHI]]
+; CHECK-NEXT: [[LOAD:%.*]] = load double, ptr [[GEP]], align 8
+; CHECK-NEXT: [[FADD:%.*]] = fadd double [[LOAD]], 1.000000e+00
+; CHECK-NEXT: store double [[FADD]], ptr [[GEP]], align 8
+; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
+; CHECK-NEXT: [[EC:%.*]] = icmp ult i64 [[IV_NEXT]], 1024
+; CHECK-NEXT: br i1 [[EC]], label %[[LOOP]], label %[[EXIT]], !llvm.loop [[LOOP7:![0-9]+]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]
+ br i1 %c, label %bar, label %foo
+
+foo:
+ %foo.res = add i64 %iv, -1
+ br label %latch
+
+bar:
+ %bar.res = add i64 %iv, -1
----------------
lukel97 wrote:
Unfortunately LAA starts to complain that it can't prove there's no memory conflicts if we return different values. But good point, I added a store to one of the blocks in 9df7ab2c123e70d570e23470fc0b391a1b9b8503 so at least the blocks aren't trivially identical. It's a bit closer to the original test case, and can still recreate the crash.
https://github.com/llvm/llvm-project/pull/172261
More information about the llvm-commits
mailing list