[llvm] bcfbba1 - [llvm] Compare std::optional<T> to values directly (NFC) (#143913)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 13 08:11:24 PDT 2025
Author: Kazu Hirata
Date: 2025-06-13T08:11:20-07:00
New Revision: bcfbba12e6754e0a2a5a1c8e3aac3a24316bba2d
URL: https://github.com/llvm/llvm-project/commit/bcfbba12e6754e0a2a5a1c8e3aac3a24316bba2d
DIFF: https://github.com/llvm/llvm-project/commit/bcfbba12e6754e0a2a5a1c8e3aac3a24316bba2d.diff
LOG: [llvm] Compare std::optional<T> to values directly (NFC) (#143913)
This patch transforms:
X && *X == Y
to:
X == Y
where X is of std::optional<T>, and Y is of T or similar.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/IR/Attributes.cpp
Removed:
################################################################################
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