[llvm] 253f24c - [InstCombine] Remove custom and(trunc(and(x, c1)), c2) fold

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 07:43:36 PDT 2020


Author: Simon Pilgrim
Date: 2020-10-16T15:43:10+01:00
New Revision: 253f24cf4c455f732423ef8ddf230b111ea41bee

URL: https://github.com/llvm/llvm-project/commit/253f24cf4c455f732423ef8ddf230b111ea41bee
DIFF: https://github.com/llvm/llvm-project/commit/253f24cf4c455f732423ef8ddf230b111ea41bee.diff

LOG: [InstCombine] Remove custom and(trunc(and(x,c1)),c2) fold

This is more correctly handled by canEvaluateTruncated (one use checks etc.) and covers all the tests cases that were added for this fold.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index fe585e43cf3d..8f28d2568c5a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1871,22 +1871,6 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
         if (Instruction *Res = OptAndOp(Op0I, Op0CI, AndRHS, I))
           return Res;
     }
-
-    // If this is an integer truncation, and if the source is an 'and' with
-    // immediate, transform it.  This frequently occurs for bitfield accesses.
-    {
-      Value *X = nullptr; ConstantInt *YC = nullptr;
-      if (match(Op0, m_Trunc(m_And(m_Value(X), m_ConstantInt(YC))))) {
-        // Change: and (trunc (and X, YC) to T), C2
-        // into  : and (trunc X to T), trunc(YC) & C2
-        // This will fold the two constants together, which may allow
-        // other simplifications.
-        Value *NewCast = Builder.CreateTrunc(X, I.getType(), "and.shrunk");
-        Constant *C3 = ConstantExpr::getTrunc(YC, I.getType());
-        C3 = ConstantExpr::getAnd(C3, AndRHS);
-        return BinaryOperator::CreateAnd(NewCast, C3);
-      }
-    }
   }
 
   if (Instruction *Z = narrowMaskedBinOp(I))


        


More information about the llvm-commits mailing list