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

hfinkel@anl.gov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 06:23:16 PDT 2015

hfinkel added a subscriber: hfinkel.

Comment at: include/llvm/IR/PatternMatch.h:961
@@ -981,1 +960,3 @@
+    auto SPR = matchSelectPattern(V, LHS, RHS);
+    return Pred_t::match(SPR) && L.match(LHS) && R.match(RHS);
I think this makes sense, but I wonder if we should now swap the order of the checks here to check L.match and R.match first. The current ordering certainly made sense because the predicate checks done before calling those functions were cheap. Calling matchSelectPattern, however, calls isKnownNonZero (at least for integer comparisons), and that can get expensive. I'd recommend that we not call matchSelectPattern until the end. My suggestion is that we:

 1. Check that V is a SelectInst (and maybe that SI->getCondition() is a CmpInst)
 2. Check L.match(LHS) && R.match(RHS)
 3. Call matchSelectPattern and check Pred_t::match(SPR)



More information about the llvm-commits mailing list