[llvm] [DAG] Improved ISD::SHL handling in isKnownToBeAPowerOfTwo (PR #181882)
Aadarsh Keshri via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 17 11:00:38 PST 2026
https://github.com/Aadarsh-Keshri created https://github.com/llvm/llvm-project/pull/181882
Did the code changes as suggested in issue #181650
DAG tests are yet to be added.
>From 78e03d2505d2fda39360fae61a572520001e4e88 Mon Sep 17 00:00:00 2001
From: Aadarsh-Keshri <keshri.aadarsh123 at gmail.com>
Date: Tue, 17 Feb 2026 23:44:57 +0530
Subject: [PATCH] [DAG] Improved ISD::SHL handling in isKnownToBeAPowerOfTwo
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 581553d41cb6d..707e24120514c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4712,10 +4712,12 @@ bool SelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val,
case ISD::SHL: {
// A left-shift of a constant one will have exactly one bit set because
// shifting the bit off the end is undefined.
- auto *C = isConstOrConstSplat(Val.getOperand(0));
+ auto *C = isConstOrConstSplat(Val.getOperand(0), DemandedElts);
if (C && C->getAPIntValue() == 1)
return true;
- return isKnownToBeAPowerOfTwo(Val.getOperand(0), /*OrZero=*/false,
+ if (!(OrZero || isKnownNeverZero(Val, Depth)))
+ return false;
+ return isKnownToBeAPowerOfTwo(Val.getOperand(0), DemandedElts, OrZero,
Depth + 1) &&
isKnownNeverZero(Val, Depth);
}
More information about the llvm-commits
mailing list