[llvm] b3c82ba - [KnownBits] Remove unneccessary calls to std::optional<bool> constructor. NFC (#181959)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 18 08:52:13 PST 2026
Author: Craig Topper
Date: 2026-02-18T08:52:08-08:00
New Revision: b3c82bafc75f0dfa8c2632868e13444787f0fce2
URL: https://github.com/llvm/llvm-project/commit/b3c82bafc75f0dfa8c2632868e13444787f0fce2
DIFF: https://github.com/llvm/llvm-project/commit/b3c82bafc75f0dfa8c2632868e13444787f0fce2.diff
LOG: [KnownBits] Remove unneccessary calls to std::optional<bool> constructor. NFC (#181959)
We can return a bool and let the compiler insert the constructor call.
Added:
Modified:
llvm/lib/Support/KnownBits.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 58d21154fed08..07e7781d0839d 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -632,31 +632,31 @@ KnownBits KnownBits::clmul(const KnownBits &LHS, const KnownBits &RHS) {
std::optional<bool> KnownBits::eq(const KnownBits &LHS, const KnownBits &RHS) {
if (LHS.isConstant() && RHS.isConstant())
- return std::optional<bool>(LHS.getConstant() == RHS.getConstant());
+ return LHS.getConstant() == RHS.getConstant();
if (LHS.One.intersects(RHS.Zero) || RHS.One.intersects(LHS.Zero))
- return std::optional<bool>(false);
+ return false;
return std::nullopt;
}
std::optional<bool> KnownBits::ne(const KnownBits &LHS, const KnownBits &RHS) {
if (std::optional<bool> KnownEQ = eq(LHS, RHS))
- return std::optional<bool>(!*KnownEQ);
+ return !*KnownEQ;
return std::nullopt;
}
std::optional<bool> KnownBits::ugt(const KnownBits &LHS, const KnownBits &RHS) {
// LHS >u RHS -> false if umax(LHS) <= umax(RHS)
if (LHS.getMaxValue().ule(RHS.getMinValue()))
- return std::optional<bool>(false);
+ return false;
// LHS >u RHS -> true if umin(LHS) > umax(RHS)
if (LHS.getMinValue().ugt(RHS.getMaxValue()))
- return std::optional<bool>(true);
+ return true;
return std::nullopt;
}
std::optional<bool> KnownBits::uge(const KnownBits &LHS, const KnownBits &RHS) {
if (std::optional<bool> IsUGT = ugt(RHS, LHS))
- return std::optional<bool>(!*IsUGT);
+ return !*IsUGT;
return std::nullopt;
}
@@ -671,16 +671,16 @@ std::optional<bool> KnownBits::ule(const KnownBits &LHS, const KnownBits &RHS) {
std::optional<bool> KnownBits::sgt(const KnownBits &LHS, const KnownBits &RHS) {
// LHS >s RHS -> false if smax(LHS) <= smax(RHS)
if (LHS.getSignedMaxValue().sle(RHS.getSignedMinValue()))
- return std::optional<bool>(false);
+ return false;
// LHS >s RHS -> true if smin(LHS) > smax(RHS)
if (LHS.getSignedMinValue().sgt(RHS.getSignedMaxValue()))
- return std::optional<bool>(true);
+ return true;
return std::nullopt;
}
std::optional<bool> KnownBits::sge(const KnownBits &LHS, const KnownBits &RHS) {
if (std::optional<bool> KnownSGT = sgt(RHS, LHS))
- return std::optional<bool>(!*KnownSGT);
+ return !*KnownSGT;
return std::nullopt;
}
More information about the llvm-commits
mailing list