[llvm] [SelectionDAG] Resolve TODO: Use signedAddMayOverflow (PR #85586)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 17 15:04:28 PDT 2024
https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/85586
This will result in more accurate results.
>From 8464e1422fd3416ab7532b6d12d218737cc72473 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Sun, 17 Mar 2024 18:04:03 -0400
Subject: [PATCH] [SelectionDAG] Resolve TODO: Use signedAddMayOverflow
This will result in more accurate results.
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 2670f48aebcff5..831fef27e5410c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4125,8 +4125,13 @@ SelectionDAG::computeOverflowForSignedAdd(SDValue N0, SDValue N1) const {
if (ComputeNumSignBits(N0) > 1 && ComputeNumSignBits(N1) > 1)
return OFK_Never;
- // TODO: Add ConstantRange::signedAddMayOverflow handling.
- return OFK_Sometime;
+ KnownBits N0Known = computeKnownBits(N0);
+ KnownBits N1Known = computeKnownBits(N1);
+
+ ConstantRange N0Range = ConstantRange::fromKnownBits(N0Known, false);
+ ConstantRange N1Range = ConstantRange::fromKnownBits(N1Known, false);
+
+ return mapOverflowResult(N0Range.signedAddMayOverflow(N1Range));
}
SelectionDAG::OverflowKind
More information about the llvm-commits
mailing list