[llvm] [DAG] Fix missing ForSigned argument in computeConstantRangeIncludingKnownBits (PR #188889)

Jim Lin via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 18:00:41 PDT 2026


https://github.com/tclin914 created https://github.com/llvm/llvm-project/pull/188889

The DemandedElts overload of computeConstantRangeIncludingKnownBits passed Depth (unsigned) to computeConstantRange where ForSigned (bool) was expected.  The implicit conversion silently dropped the caller's ForSigned flag and used Depth as the signedness indicator.

Introduced in a6a66a4e6915.

>From eb5638f879367e1425b2f5842016977357eb7c9b Mon Sep 17 00:00:00 2001
From: Jim Lin <jim at andestech.com>
Date: Fri, 27 Mar 2026 08:44:33 +0800
Subject: [PATCH] [DAG] Fix missing ForSigned argument in
 computeConstantRangeIncludingKnownBits

The DemandedElts overload of computeConstantRangeIncludingKnownBits
passed Depth (unsigned) to computeConstantRange where ForSigned (bool)
was expected.  The implicit conversion silently dropped the caller's
ForSigned flag and used Depth as the signedness indicator.

Introduced in a6a66a4e6915.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply at anthropic.com>
---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 85f3fca29f4ad..7badb375c06a1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4706,7 +4706,7 @@ ConstantRange SelectionDAG::computeConstantRangeIncludingKnownBits(
     unsigned Depth) const {
   KnownBits Known = computeKnownBits(Op, DemandedElts, Depth);
   ConstantRange CR1 = ConstantRange::fromKnownBits(Known, ForSigned);
-  ConstantRange CR2 = computeConstantRange(Op, DemandedElts, Depth);
+  ConstantRange CR2 = computeConstantRange(Op, DemandedElts, ForSigned, Depth);
   ConstantRange::PreferredRangeType RangeType =
       ForSigned ? ConstantRange::Signed : ConstantRange::Unsigned;
   return CR1.intersectWith(CR2, RangeType);



More information about the llvm-commits mailing list