[PATCH] D108112: [LoopIdiom] let LIR fold memset pointer / stride SCEV regarding loop guards

Bardia Mahjour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 16 10:02:24 PDT 2021


bmahjour added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:310
 
+// The Folder will fold expressions that is guarded by the loop entry.
+class SCEVFolder : public SCEVRewriteVisitor<SCEVFolder> {
----------------
that is -> that are


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:319
+  const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
+    // If expression is guarded by CurLoop to be greater of equal to zero
+    // then convert sext to zext. Otherwise return the original expression.
----------------
greater of -> greater or


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:321-325
+    if (SE.isLoopEntryGuardedByCond(CurLoop, ICmpInst::ICMP_SGE, Expr,
+                                    SE.getZero(Expr->getType())) == false)
+      return Expr;
+    return SE.getZeroExtendExpr(visit(Expr->getOperand()), Expr->getType());
+  }
----------------
```
    if (SE.isLoopEntryGuardedByCond(CurLoop, ICmpInst::ICMP_SGE, Expr,
                                    SE.getZero(Expr->getType())))
      return SE.getZeroExtendExpr(visit(Expr->getOperand()), Expr->getType());
   return Expr;
  }

```


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:989
     if (PositiveStrideSCEV != MemsetSizeSCEV) {
-      // TODO: folding can be done to the SCEVs
       // The folding is to fold expressions that is covered by the loop guard
       // at loop entry. After the folding, compare again and proceed
----------------
fold expressions that is -> fold an expression that is


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:991
       // at loop entry. After the folding, compare again and proceed
       // optimization if equal.
+      SCEVFolder Folder(*SE, CurLoop);
----------------
proceed optimization if equal. -> proceed with optimization, if equal.


================
Comment at: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp:996
+
+      LLVM_DEBUG(dbgs() << "  Try to fold SCEV with respect to loop guard\n"
+                        << "    FoldedMemsetSize: " << *FoldedMemsetSize << "\n"
----------------
with respect to -> based on


================
Comment at: llvm/test/Transforms/LoopIdiom/memset-runtime.ll:116
+;       int *arr = ar + i * m * o + j * o;
+;       memset(arr, 0, o * sizeof(int));
+;     }
----------------
Given that the stride is `o x 4`, it's not clear how the loop guard can help make assumptions about sign/zero extension. Can you explain this example in the description section?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108112/new/

https://reviews.llvm.org/D108112



More information about the llvm-commits mailing list