[PATCH] D81151: [InstCombine] Simplify compare of Phi with constant inputs against a constant

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 05:57:20 PDT 2020


lebedev.ri added a reviewer: lebedev.ri.
lebedev.ri added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1463
+  if (auto *Phi = dyn_cast<PHINode>(Op0))
+    if (Phi->hasOneUse() &&
+        all_of(Phi->operands(), [](Value *V) { return isa<ConstantInt>(V); })) {
----------------
I don't think you need one-use check - you produce a single instruction,
and root icmp from which you started matching always goes away (is replaced by new phi)


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1464
+    if (Phi->hasOneUse() &&
+        all_of(Phi->operands(), [](Value *V) { return isa<ConstantInt>(V); })) {
+      Type *Ty = Cmp.getType();
----------------
Why ConstantInt? What would be wrong with vector of integers? What about undef? Constant exprs?


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1473
+            cast<ConstantInt>(Phi->getIncomingValueForBlock(Predecessor));
+        auto *BoolInput = SimplifyICmpInst(Pred, Input, CI, Q);
+        NewPhi->addIncoming(BoolInput, Predecessor);
----------------
I'd think you simply want `ConstantExpr::getCompare()`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81151/new/

https://reviews.llvm.org/D81151





More information about the llvm-commits mailing list