[llvm] [VPlan] Use llvm.masked.{u, s}{div, rem} for predicated division (PR #191377)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 06:51:47 PDT 2026
================
@@ -120,9 +122,8 @@ define void @sdiv_feeding_gep_predicated(ptr %dst, i32 %x, i64 %M, i64 %conv6, i
; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 2 x i64> [ [[TMP15]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
; CHECK-NEXT: [[TMP22:%.*]] = icmp ule <vscale x 2 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
; CHECK-NEXT: [[TMP23:%.*]] = select <vscale x 2 x i1> [[ACTIVE_LANE_MASK]], <vscale x 2 x i1> [[TMP22]], <vscale x 2 x i1> zeroinitializer
-; CHECK-NEXT: [[TMP24:%.*]] = extractelement <vscale x 2 x i1> [[TMP23]], i32 0
-; CHECK-NEXT: [[TMP25:%.*]] = select i1 [[TMP24]], i64 [[CONV6]], i64 1
-; CHECK-NEXT: [[TMP26:%.*]] = sdiv i64 [[M]], [[TMP25]]
+; CHECK-NEXT: [[TMP12:%.*]] = call <vscale x 2 x i64> @llvm.masked.sdiv.nxv2i64(<vscale x 2 x i64> [[BROADCAST_SPLAT]], <vscale x 2 x i64> [[BROADCAST_SPLAT2]], <vscale x 2 x i1> [[TMP23]])
----------------
lukel97 wrote:
It turns out this is because legalizeAndOptimize inductions previously converted the VPWidenRecipe to a replicate recipe. But after investigating it for a bit I'm not worried about this particular diff, the sdiv gets removed either way by LSR so there's no change in the resulting codegen.
And usually the cost model should take care of setting the widening decision to scalarize and generate a replicate recipe anyway. E.g. the sdiv in this loop isn't widened:
```c
void f(int x, int y, int *p, int n) {
for (int i = 0; i < n; i++)
if (i <= x)
p[i] = x / y;
}
```
https://github.com/llvm/llvm-project/pull/191377
More information about the llvm-commits
mailing list