[llvm] [SelectionDAG] Use SDNode::op_iterator instead of SDNodeIterator. NFC (PR #122147)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 14:49:08 PST 2025
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/122147
>From 23ca7cff12a3793ff8b75193bffbfa023498f2f3 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 8 Jan 2025 10:07:44 -0800
Subject: [PATCH 1/2] [SelectionDAG] Use SDNode::op_iterator instead of
SDNodeIterator. NFC
I think SDNodeIterator primarily exists because GraphTraits requires
an iterator that dereferences to SDNode*. op_iterator dereferences to
SDUse* which is implicitly convertible to SDValue.
This piece of code can use SDValue instead of SDNode* so we should
prefer to use the the more common op_iterator.
---
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 9f57884eae04df..5099833ce86cbf 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -2986,8 +2986,7 @@ bool TargetLowering::SimplifyDemandedBits(
DemandedBits.isSubsetOf(Known.Zero | Known.One)) {
// Avoid folding to a constant if any OpaqueConstant is involved.
const SDNode *N = Op.getNode();
- for (SDNode *Op :
- llvm::make_range(SDNodeIterator::begin(N), SDNodeIterator::end(N))) {
+ for (SDValue Op : N->ops()) {
if (auto *C = dyn_cast<ConstantSDNode>(Op))
if (C->isOpaque())
return false;
>From 69b80e31458cfef1b58eb414757f6e504cc0945b Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 8 Jan 2025 14:45:21 -0800
Subject: [PATCH 2/2] fixup! Use Op->ops(). Use llvm::any_of.
---
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 5099833ce86cbf..56194e2614af2d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -2985,12 +2985,11 @@ bool TargetLowering::SimplifyDemandedBits(
if (!isTargetCanonicalConstantNode(Op) &&
DemandedBits.isSubsetOf(Known.Zero | Known.One)) {
// Avoid folding to a constant if any OpaqueConstant is involved.
- const SDNode *N = Op.getNode();
- for (SDValue Op : N->ops()) {
- if (auto *C = dyn_cast<ConstantSDNode>(Op))
- if (C->isOpaque())
- return false;
- }
+ if (llvm::any_of(Op->ops(), [](SDValue V) {
+ auto *C = dyn_cast<ConstantSDNode>(V);
+ return C && C->isOpaque();
+ }))
+ return false;
if (VT.isInteger())
return TLO.CombineTo(Op, TLO.DAG.getConstant(Known.One, dl, VT));
if (VT.isFloatingPoint())
More information about the llvm-commits
mailing list