[PATCH] D34822: [LVI] Constant-propagate a zero extension of the switch condition value through case edges

Hiroshi Yamauchi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 16:39:55 PDT 2017


yamauchi added inline comments.


================
Comment at: lib/Analysis/LazyValueInfo.cpp:1465
+      if (User* Usr = dyn_cast<User>(Val)) {
+        if (isa<IntegerType>(Val->getType())) {
+          for (unsigned i = 0; i < Usr->getNumOperands(); ++i) {
----------------
sanjoy wrote:
> Does this logic subsume the logic in line 1431?  And can we write the switch case case (no pun intended! :) ) in the same way?  If so, I'd suggest pulling this logic out into a function and calling it once here and once from the switch-case block.
No, this logic does not subsume the logic in line 1431 (I verified that by commenting it out and running the tests.) This is because the 1431 logic handles the cases where 'Condition' is an operand of 'Val' whereas this logic handles the cases where 'Condition' is *not* an operand of 'Val', but one ('Op') of the operands of 'Val' can be inferred through the value of 'Condition'. Note this logic calls getValueFromCondition for 'Op'.

I moved the 1431 logic here and combined them.

I also factored out some common logic out to constantFoldUser() and simplified its call sites.




================
Comment at: lib/Analysis/LazyValueInfo.cpp:1488
+    Value* Condition = SI->getCondition();
+    if (!isa<IntegerType>(Val->getType()))
       return false;
----------------
sanjoy wrote:
> I think this can be an assert -- switch only allows integer conditions.
I assume 'Val' can be any value live through the switch for which we're trying to find its value on this edge, and can be of any type?


https://reviews.llvm.org/D34822





More information about the llvm-commits mailing list