Skip to content

Conversation

@VoltrexKeyva
Copy link
Member

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

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Jun 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-llvm-analysis

Author: Mohammed Keyvanzadeh (VoltrexKeyva)

Changes

Use isa_and_nonnull&lt;T&gt;(v) instead of v &amp;&amp; isa&lt;T&gt;(v), where v is evaluated twice in the latter.


Full diff: https://github.com/llvm/llvm-project/pull/95327.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/ConstantFolding.cpp (+2-2)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index e0f5bf0ab8365..46a7f832f6761 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;
     }
@@ -218,7 +218,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

@VoltrexKeyva VoltrexKeyva force-pushed the prefer-isa-and-nonnull branch from 237ea51 to 8122d33 Compare June 14, 2024 22:56
Use `isa_and_nonnull<T>(v)` instead of `v && isa<T>(v)`, where `v` is
evaluated twice in the latter.
@VoltrexKeyva VoltrexKeyva force-pushed the prefer-isa-and-nonnull branch from 8122d33 to a28bcd0 Compare June 14, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants