[llvm] 721b796 - [llvm] prefer isa_and_nonnull over v && isa (#112541)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 08:42:08 PDT 2024


Author: Mohammed Keyvanzadeh
Date: 2024-10-18T19:12:04+03:30
New Revision: 721b796809eca6e67dcefe45a3498764dda3117d

URL: https://github.com/llvm/llvm-project/commit/721b796809eca6e67dcefe45a3498764dda3117d
DIFF: https://github.com/llvm/llvm-project/commit/721b796809eca6e67dcefe45a3498764dda3117d.diff

LOG: [llvm] prefer isa_and_nonnull over v && isa (#112541)

Use `isa_and_nonnull<T>(v)` instead of `v && isa<T>(v)`, where `v` is
evaluated twice in the latter.

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index da0fd1f07c83e4..74df67a4ff9b43 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -82,7 +82,7 @@ static Constant *foldConstVectorToAPInt(APInt &Result, Type *DestTy,
     else
       Element = C->getAggregateElement(i);
 
-    if (Element && isa<UndefValue>(Element)) {
+    if (isa_and_nonnull<UndefValue>(Element)) {
       Result <<= BitShift;
       continue;
     }
@@ -219,7 +219,7 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
       unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize*(Ratio-1);
       for (unsigned j = 0; j != Ratio; ++j) {
         Constant *Src = C->getAggregateElement(SrcElt++);
-        if (Src && isa<UndefValue>(Src))
+        if (isa_and_nonnull<UndefValue>(Src))
           Src = Constant::getNullValue(
               cast<VectorType>(C->getType())->getElementType());
         else


        


More information about the llvm-commits mailing list