[llvm] [LV]Partial replace the mask for div/rem safe-divisor select (PR #165530)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 6 01:13:50 PST 2025


================
@@ -7752,6 +7752,12 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I,
     if (CM.isPredicatedInst(I)) {
       SmallVector<VPValue *> Ops(Operands);
       VPValue *Mask = getBlockInMask(Builder.getInsertBlock());
+      if (auto *Inst = dyn_cast<VPInstruction>(Mask)) {
+        if (Inst->getOpcode() == VPInstruction::LogicalAnd) {
+          VPValue *Zero = Plan.getConstantInt(I->getType(), 0);
+          Mask = Builder.createICmp(CmpInst::ICMP_NE, Ops[1], Zero);
+        }
+      }
----------------
lukel97 wrote:

Is there a reason why we need to only do this when the mask is an and? I think it should be correct to always just replace the SafeRHS with `(select (icmp ne rhs, 0), rhs, 1)` for any mask

https://github.com/llvm/llvm-project/pull/165530


More information about the llvm-commits mailing list