[PATCH] D29107: Fix a bug when unswitching on partial LIV for SwitchInst
Sanjoy Das via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 16:18:07 PST 2017
sanjoy added a comment.
I would say the problem here is that we're not doing a good enough job of choosing a good value to unswitch on (and not that we're unswitching on the wrong "type" of value). That is, say we have a switch on `Inv & Var` (`Inv` being the loop invariant value) that dispatches on `0`, `200` and `300`. In such a case, we should clearly unswitch on `Inv == 0` to simplify the switch to a direct branch to the `(Inv & Var) == 0` case in one of the loops. Similar logic follows if we have a switch on `Inv | Var` and one of the cases is `-1`.
So I think the patch should be structured as:
- Keep `FindLIVLoopCondition` the same (maybe return a bit of extra information to make the next steps easier)
- In `processCurrentLoop`, check to see if the expression we're switching on simplifies to any of the case values given some constant value for what was returned by `FindLIVLoopCondition`
- If there is such a constant value, unswitch on that and profit
- Else give up
================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:442
+ if (BO->getType()->isIntegerTy(1) &&
+ (BO->getOpcode() == Instruction::And ||
+ BO->getOpcode() == Instruction::Or)) {
----------------
Did you clang-format this bit?
https://reviews.llvm.org/D29107
More information about the llvm-commits
mailing list