[llvm] [llvm] Compare std::optional<T> to values directly (NFC) (PR #143913)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 07:44:53 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/143913
This patch transforms:
X && *X == Y
to:
X == Y
where X is of std::optional<T>, and Y is of T or similar.
>From e54293d113bab9b139217e91e093addcfae0438b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 10 Jun 2025 23:56:32 -0700
Subject: [PATCH] [llvm] Compare std::optional<T> to values directly (NFC)
This patch transforms:
X && *X == Y
to:
X == Y
where X is of std::optional<T>, and Y is of T or similar.
---
llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
llvm/lib/IR/Attributes.cpp | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 139a0b81e299b..64a0f4641250c 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2132,7 +2132,7 @@ static bool mayFoldConstrained(ConstrainedFPIntrinsic *CI,
// If evaluation raised FP exception, the result can depend on rounding
// mode. If the latter is unknown, folding is not possible.
- if (ORM && *ORM == RoundingMode::Dynamic)
+ if (ORM == RoundingMode::Dynamic)
return false;
// If FP exceptions are ignored, fold the call, even if such exception is
@@ -2418,7 +2418,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
if (IntrinsicID == Intrinsic::experimental_constrained_rint &&
St == APFloat::opInexact) {
std::optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
- if (EB && *EB == fp::ebStrict)
+ if (EB == fp::ebStrict)
return nullptr;
}
} else if (U.isSignaling()) {
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index ed485f9656996..bfb32ff9995d1 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -295,7 +295,7 @@ Attribute Attribute::getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI) {
Attribute
Attribute::getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg,
const std::optional<unsigned> &NumElemsArg) {
- assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) &&
+ assert(!(ElemSizeArg == 0 && NumElemsArg == 0) &&
"Invalid allocsize arguments -- given allocsize(0, 0)");
return get(Context, AllocSize, packAllocSizeArgs(ElemSizeArg, NumElemsArg));
}
More information about the llvm-commits
mailing list