[PATCH] D29037: Constant fold switch inst when looking for trivial conditions to unswitch on.

Xin Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 14:23:52 PST 2017


trentxintong added inline comments.


================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:922
+        const DataLayout &DL = I->getModule()->getDataLayout();
+        if (Constant *Fold = ConstantFoldInstruction(I, DL))
+          Cond = Fold;
----------------
efriedma wrote:
> Is this likely to actually do anything in practice...? Most passes (including LoopUnswitch itself) will constant-fold newly generated code.
I agree that the constants probably have been folded at this point. The only constants remaining are likely to be the ones generated by unswitching (Even those ones are likely to be folded away by SimplifyCode in LoopUnswitch) or maybe we have some pass ordering problems. 

I am fine dropping the ConstantFoldInstruction, as this does add some compilation time to the pass.


================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:928
+      // At this point, the switched value is a constant.
+      assert(isa<Constant>(Cond) && "Switched value must be a constant");
+      bool FoundDest = false;
----------------
efriedma wrote:
> Checking for a Constant isn't good enough here: you need a ConstantInt.
Yes, this has to be a constant int of abitrary width.


https://reviews.llvm.org/D29037





More information about the llvm-commits mailing list