[llvm] 440af98 - [InstCombine] Avoid use of ConstantExpr::getShl()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 07:27:26 PDT 2024


Author: Nikita Popov
Date: 2024-06-18T16:27:17+02:00
New Revision: 440af98a04402929b8c644b983add05cf420b5f8

URL: https://github.com/llvm/llvm-project/commit/440af98a04402929b8c644b983add05cf420b5f8
DIFF: https://github.com/llvm/llvm-project/commit/440af98a04402929b8c644b983add05cf420b5f8.diff

LOG: [InstCombine] Avoid use of ConstantExpr::getShl()

Use IRBuilder instead. Also use ImmConstant to guarantee that this
will fold.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 6a6bdba3fa70a..7b1268939e9c4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -749,10 +749,10 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
     }
 
     Constant *C;
-    if (match(Src, m_OneUse(m_LShr(m_Value(X), m_Constant(C))))) {
+    if (match(Src, m_OneUse(m_LShr(m_Value(X), m_ImmConstant(C))))) {
       // trunc (lshr X, C) to i1 --> icmp ne (and X, C'), 0
       Constant *One = ConstantInt::get(SrcTy, APInt(SrcWidth, 1));
-      Constant *MaskC = ConstantExpr::getShl(One, C);
+      Value *MaskC = Builder.CreateShl(One, C);
       Value *And = Builder.CreateAnd(X, MaskC);
       return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
     }
@@ -760,7 +760,7 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
                                    m_Deferred(X))))) {
       // trunc (or (lshr X, C), X) to i1 --> icmp ne (and X, C'), 0
       Constant *One = ConstantInt::get(SrcTy, APInt(SrcWidth, 1));
-      Constant *MaskC = ConstantExpr::getShl(One, C);
+      Value *MaskC = Builder.CreateShl(One, C);
       Value *And = Builder.CreateAnd(X, Builder.CreateOr(MaskC, One));
       return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
     }


        


More information about the llvm-commits mailing list