[llvm] [llvm] Fix fabs simplification (PR #152825)
Oliver Hunt via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 21:24:04 PDT 2025
https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/152825
>From 4bebc84bfc096e0adbd785a3b0addf0221f1ff3b Mon Sep 17 00:00:00 2001
From: Oliver Hunt <oliver at apple.com>
Date: Fri, 8 Aug 2025 20:58:57 -0700
Subject: [PATCH] [llvm] Fix fabs simplification
The existing code hits the std::optional<bool> is of comparing
to a bool being "correct" for the std::optional and the intended
comparison.
This corrects the comparison while reinforcing the idea that we
need some way to diagnose this.
Fixes #152824
---
llvm/lib/Analysis/InstructionSimplify.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 5907e21065331..622c67200ac51 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -6304,7 +6304,8 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
Value *X;
switch (IID) {
case Intrinsic::fabs:
- if (computeKnownFPSignBit(Op0, Q) == false)
+ if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(Op0, Q);
+ !KnownSignBit || *KnownSignBit == false)
return Op0;
break;
case Intrinsic::bswap:
More information about the llvm-commits
mailing list