[PATCH] D34025: [SCEV] Teach SCEVExpander to expand BinPow

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 18 20:17:13 PDT 2017


mkazantsev added inline comments.


================
Comment at: lib/Analysis/ScalarEvolutionExpander.cpp:775
+    Value *Result = nullptr;
+    if (Exponent & 1u)
+      Result = P;
----------------
sanjoy wrote:
> Can you get rid of this conditional and instead start `BinExp` from `1`?
That would make the loop a bit messy, since we are generating the current power differently for p = 1 and the rest, and because we need to generate the next operand before (possibly) using it. I will need an if in loop in this case, something like

  for (unsigned BinExp = 1; BinExp <= Exponent; BinExp <<= 1) {
    P = BinExp == 1 ? expandCodeFor(I->second, Ty) : InsertBinop(Instruction::Mul, P, P);
    if (Exponent & BinExp)
      Result = Result ? InsertBinop(Instruction::Mul, Result, P) : P;
  }

It is hardly easier to read and worse performance-wise.


https://reviews.llvm.org/D34025





More information about the llvm-commits mailing list