[llvm] r274670 - [InstCombine] use more specific pattern matchers; NFCI

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 14:01:26 PDT 2016


Author: spatel
Date: Wed Jul  6 16:01:26 2016
New Revision: 274670

URL: http://llvm.org/viewvc/llvm-project?rev=274670&view=rev
Log:
[InstCombine] use more specific pattern matchers; NFCI

Follow-up from r274465: we don't need to capture the value in these cases, 
so just match the constant that we're looking for. m_One/m_Zero work with
vector splats as well as scalars.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=274670&r1=274669&r2=274670&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Wed Jul  6 16:01:26 2016
@@ -920,22 +920,20 @@ Instruction *InstCombiner::visitSelectIn
 
   if (SI.getType()->getScalarType()->isIntegerTy(1) &&
       TrueVal->getType() == CondVal->getType()) {
-    const APInt *TrueC;
-    if (match(TrueVal, m_APInt(TrueC))) {
-      if (TrueC->isAllOnesValue()) {
-        // Change: A = select B, true, C --> A = or B, C
-        return BinaryOperator::CreateOr(CondVal, FalseVal);
-      }
+    if (match(TrueVal, m_One())) {
+      // Change: A = select B, true, C --> A = or B, C
+      return BinaryOperator::CreateOr(CondVal, FalseVal);
+    }
+    if (match(TrueVal, m_Zero())) {
       // Change: A = select B, false, C --> A = and !B, C
       Value *NotCond = Builder->CreateNot(CondVal, "not." + CondVal->getName());
       return BinaryOperator::CreateAnd(NotCond, FalseVal);
     }
-    const APInt *FalseC;
-    if (match(FalseVal, m_APInt(FalseC))) {
-      if (*FalseC == 0) {
-        // Change: A = select B, C, false --> A = and B, C
-        return BinaryOperator::CreateAnd(CondVal, TrueVal);
-      }
+    if (match(FalseVal, m_Zero())) {
+      // Change: A = select B, C, false --> A = and B, C
+      return BinaryOperator::CreateAnd(CondVal, TrueVal);
+    }
+    if (match(FalseVal, m_One())) {
       // Change: A = select B, C, true --> A = or !B, C
       Value *NotCond = Builder->CreateNot(CondVal, "not." + CondVal->getName());
       return BinaryOperator::CreateOr(NotCond, TrueVal);




More information about the llvm-commits mailing list