[llvm] [llvm] prefer isa_and_nonnull over v && isa (PR #112541)
Mohammed Keyvanzadeh via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 06:23:15 PDT 2024
https://github.com/VoltrexKeyva created https://github.com/llvm/llvm-project/pull/112541
Use `isa_and_nonnull<T>(v)` instead of `v && isa<T>(v)`, where `v` is evaluated twice in the latter.
>From 43f84855c7d50a2688fde2a48a5b228b92aa0b2c Mon Sep 17 00:00:00 2001
From: Mohammed Keyvanzadeh <mohammadkeyvanzade94 at gmail.com>
Date: Thu, 13 Jun 2024 02:20:01 +0330
Subject: [PATCH] [llvm] prefer isa_and_nonnull over v && isa
Use `isa_and_nonnull<T>(v)` instead of `v && isa<T>(v)`, where `v` is
evaluated twice in the latter.
---
llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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
More information about the llvm-commits
mailing list