[PATCH] D24147: Lower consecutive select instructions correctly.

David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 16:30:21 PDT 2016


davidxl added inline comments.

================
Comment at: lib/CodeGen/CodeGenPrepare.cpp:4720
@@ +4719,3 @@
+  for (auto It = ASI.rbegin(); It != ASI.rend(); ++It) {
+    SelectInst *SI = *It;
+    // The select itself is replaced with a PHI Node.
----------------
There is probably no need to do reverse iteration. I suggest create a helper function 

Value *getTrueOrFalseValue(SelectInst *SI, bool isTrue, const SmallPtrSet<...>& Selects) {
   Value *V; 
   do {
      V = (isTrue? SI->getTrueValue() : SI->getFalseValue());
      VI = dyn_cast<SelectInst>(V);
      if (!VI || !Selects.count(VI))
         break;
      SI = VI;
    } while (true);
    return V;
}

Then the code below can be simplified a lot and easier to read:

PN->addIncoming(getTrueOrFalseValue(SI, true, INS), TrueBlock);
PN->addIncoming(getTrueOfFalseValue(SI, false, INS), FalseBlock);



https://reviews.llvm.org/D24147





More information about the llvm-commits mailing list