[llvm] r271554 - [InstCombine] remove guard for generating a vector select

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 11:03:05 PDT 2016


Author: spatel
Date: Thu Jun  2 13:03:05 2016
New Revision: 271554

URL: http://llvm.org/viewvc/llvm-project?rev=271554&view=rev
Log:
[InstCombine] remove guard for generating a vector select

This is effectively NFC because we already do this transform after r175380:
http://reviews.llvm.org/rL175380

and also via foldBoolSextMaskToSelect().

This change should just make it a bit more efficient to match the pattern. 
The original guard was added in r95058:
http://reviews.llvm.org/rL95058

A sampling of codegen for current in-tree targets shows no problems. This
makes sense given that we're already producing the vector selects via the
other transforms.


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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=271554&r1=271553&r2=271554&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Jun  2 13:03:05 2016
@@ -1659,12 +1659,11 @@ Instruction *InstCombiner::MatchBSwap(Bi
 /// We have an expression of the form (A&C)|(B&D).  Check if A is (cond?-1:0)
 /// and either B or D is ~(cond?-1,0) or (cond?0,-1), then we can simplify this
 /// expression to "cond ? C : D or B".
-static Instruction *MatchSelectFromAndOr(Value *A, Value *B,
+static Instruction *matchSelectFromAndOr(Value *A, Value *B,
                                          Value *C, Value *D) {
   // If A is not a select of -1/0, this cannot match.
   Value *Cond = nullptr;
-  if (!match(A, m_SExt(m_Value(Cond))) ||
-      !Cond->getType()->isIntegerTy(1))
+  if (!match(A, m_SExt(m_Value(Cond))) || !Cond->getType()->isIntegerTy(1))
     return nullptr;
 
   // ((cond?-1:0)&C) | (B&(cond?0:-1)) -> cond ? C : B.
@@ -1678,6 +1677,7 @@ static Instruction *MatchSelectFromAndOr
     return SelectInst::Create(Cond, C, D);
   if (match(B, m_SExt(m_Not(m_Specific(Cond)))))
     return SelectInst::Create(Cond, C, D);
+
   return nullptr;
 }
 
@@ -2274,18 +2274,14 @@ Instruction *InstCombiner::visitOr(Binar
     }
 
     // (A & (C0?-1:0)) | (B & ~(C0?-1:0)) ->  C0 ? A : B, and commuted variants.
-    // Don't do this for vector select idioms, the code generator doesn't handle
-    // them well yet.
-    if (!I.getType()->isVectorTy()) {
-      if (Instruction *Match = MatchSelectFromAndOr(A, B, C, D))
-        return Match;
-      if (Instruction *Match = MatchSelectFromAndOr(B, A, D, C))
-        return Match;
-      if (Instruction *Match = MatchSelectFromAndOr(C, B, A, D))
-        return Match;
-      if (Instruction *Match = MatchSelectFromAndOr(D, A, B, C))
-        return Match;
-    }
+    if (Instruction *Match = matchSelectFromAndOr(A, B, C, D))
+      return Match;
+    if (Instruction *Match = matchSelectFromAndOr(B, A, D, C))
+      return Match;
+    if (Instruction *Match = matchSelectFromAndOr(C, B, A, D))
+      return Match;
+    if (Instruction *Match = matchSelectFromAndOr(D, A, B, C))
+      return Match;
 
     // ((A&~B)|(~A&B)) -> A^B
     if ((match(C, m_Not(m_Specific(D))) &&




More information about the llvm-commits mailing list