[PATCH] D13029: [PatternMatch] Switch to using ValueTracking::matchSelectPattern for min/max matching

hfinkel@anl.gov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 27 17:27:06 PDT 2015


hfinkel accepted this revision.
hfinkel added a reviewer: hfinkel.
hfinkel added a comment.
This revision is now accepted and ready to land.

Remove the redundant check as noted, and this LGTM.


================
Comment at: include/llvm/IR/PatternMatch.h:959-962
@@ -957,5 +958,6 @@
   template <typename OpTy> bool match(OpTy *V) {
-    // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
-    auto *SI = dyn_cast<SelectInst>(V);
-    if (!SI)
+    // matchSelectPattern can get expensive, so do some early bailout checks
+    // first.
+    if (!isa<SelectInst>(V) ||
+        !isa<CmpInst>(cast<SelectInst>(V)->getCondition()))
       return false;
----------------
majnemer wrote:
> Unless I'm mistaken, isn't this what `llvm::matchSelectPattern` already does?  I'd be surprised if the extra call frame matters here.
Yea, he half-implemented my earlier suggestion by putting this check here. But, as James pointed out, he needs to call matchSelectPattern first anyway to bind LHS and RHS. Thus, as you point out, this is not needed.


Repository:
  rL LLVM

http://reviews.llvm.org/D13029





More information about the llvm-commits mailing list