Skip to content

[llvm] prefer isa_and_nonnull over v && isa #112541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024

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.

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

llvmbot commented Oct 16, 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/112541.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 3af4ae31ffe8b0..190fe80a8d2859 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

@VoltrexKeyva VoltrexKeyva merged commit 721b796 into llvm:main Oct 18, 2024
10 checks passed
@VoltrexKeyva VoltrexKeyva deleted the prefer-isa-and-nonnull branch October 18, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants