[PATCH] Select Elimination in InstCombine

David Majnemer david.majnemer at gmail.com
Tue Sep 9 00:23:21 PDT 2014


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2452-2454
@@ +2451,5 @@
+    return false;
+  if (!isa<BranchInst>(BB->getTerminator()))
+    return false;
+  BranchInst *BI = cast<BranchInst>(BB->getTerminator());
+  if (BI->getNumSuccessors() != 2)
----------------
Why not perform a dyn_cast instead?

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2457-2460
@@ +2456,6 @@
+    return false;
+  ICmpInst *IC = dyn_cast<ICmpInst>(BI->getCondition());
+  if (IC && IC->getOperand(0) != SI)
+    return false;
+  return true;
+}
----------------
This will return true if IC is null, did is this intensional?

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2955
@@ +2954,3 @@
+            // Code sequence is select - icmp.eq - br
+            int ReplaceWithOpd = 0;
+            if (Op2)
----------------
s/int/unsigned

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2972-2973
@@ +2971,4 @@
+                  ReplaceWithOpd = 2;
+            bool IsEQorNECompare = I.getPredicate() == ICmpInst::ICMP_EQ ||
+                                   I.getPredicate() == ICmpInst::ICMP_NE;
+            if (ReplaceWithOpd && IsEQorNECompare) {
----------------
This is just llvm::ICmpInst::isEquality.

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2977
@@ +2976,3 @@
+              // replace select with operand on then path for NE compares.
+              int Path = I.getPredicate() == ICmpInst::ICMP_EQ ? 1 : 0;
+              if (InstCombiner::dominatesAllUses(
----------------
echristo wrote:
> Isn't this just a boolean then?
I'd make this an unsigned, getSuccessor is asking which successor to take.  It just so happens that we are only interested in cases where there are two successors.

http://reviews.llvm.org/D5258






More information about the llvm-commits mailing list