[llvm] [LV] Don't predicate uniform divides with loop-invariant divisor. (PR #98904)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 20 06:27:18 PDT 2024


================
@@ -3710,6 +3713,15 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
   case Instruction::SDiv:
   case Instruction::SRem:
   case Instruction::URem:
+    // When folding the tail, at least one of the lanes must execute
+    // unconditionally. If the divisor is loop-invariant no predication is
+    // needed, as predication would not prevent the divide-by-0 on the executed
+    // lane.
+    if (foldTailByMasking() && !Legal->blockNeedsPredication(I->getParent()) &&
+        TheLoop->isLoopInvariant(I->getOperand(1)) &&
+        (IsKnownUniform || isUniformAfterVectorization(I, VF)))
+      return false;
----------------
fhahn wrote:

Thanks I restructured the code and generalized it so the unconditionally-executed but tail-folded cases are all handled at the ned.

Removed the IsKnownUniform requirement.

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


More information about the llvm-commits mailing list