[llvm] [llvm] Compare std::optional<T> to values directly (NFC) (PR #143913)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 07:45:40 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch transforms:
X && *X == Y
to:
X == Y
where X is of std::optional<T>, and Y is of T or similar.
---
Full diff: https://github.com/llvm/llvm-project/pull/143913.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+2-2)
- (modified) llvm/lib/IR/Attributes.cpp (+1-1)
``````````diff
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));
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/143913
More information about the llvm-commits
mailing list