[llvm] [SelectionDAG] Remove redundant vector checks (NFC) (PR #99524)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 09:29:04 PDT 2024
https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/99524
It turns out that the function already exits early if N1 is not a constant or is a vector, so simplify.
>From 41e22c38a04337b0ab49e72a0f209f880cc0ad56 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Thu, 18 Jul 2024 12:23:13 -0400
Subject: [PATCH] [SelectionDAG] Remove redundant vector checks (NFC)
It turns out that the function already exits early if N1 is not a constant or is a vector, so simplify.
---
.../CodeGen/SelectionDAG/TargetLowering.cpp | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index c3a20b5044c5f..7e38a3607cdd1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -6483,15 +6483,7 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
// Try to use leading zeros of the dividend to reduce the multiplier and
// avoid expensive fixups.
- // TODO: Support vectors.
- unsigned LeadingZeros = 0;
- if (!VT.isVector() && isa<ConstantSDNode>(N1)) {
- assert(!isOneConstant(N1) && "Unexpected divisor");
- LeadingZeros = DAG.computeKnownBits(N0).countMinLeadingZeros();
- // UnsignedDivisionByConstantInfo doesn't work correctly if leading zeros in
- // the dividend exceeds the leading zeros for the divisor.
- LeadingZeros = std::min(LeadingZeros, N1->getAsAPIntVal().countl_zero());
- }
+ unsigned KnownLeadingZeros = DAG.computeKnownBits(N0).countMinLeadingZeros();
bool UseNPQ = false, UsePreShift = false, UsePostShift = false;
SmallVector<SDValue, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
@@ -6509,8 +6501,16 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
PreShift = PostShift = DAG.getUNDEF(ShSVT);
MagicFactor = NPQFactor = DAG.getUNDEF(SVT);
} else {
+
+ // Try to use leading zeros of the dividend to reduce the multiplier and
+ // avoid expensive fixups.
+ unsigned LeadingZeros = DAG.computeKnownBits(N0).countMinLeadingZeros();
+ // UnsignedDivisionByConstantInfo doesn't work correctly if leading zeros
+ // in the dividend exceeds the leading zeros for the divisor.
+ LeadingZeros = std::min(LeadingZeros, N1->getAsAPIntVal().countl_zero());
UnsignedDivisionByConstantInfo magics =
- UnsignedDivisionByConstantInfo::get(Divisor, LeadingZeros);
+ UnsignedDivisionByConstantInfo::get(
+ Divisor, std::min(KnownLeadingZeros, Divisor.countl_zero()));
MagicFactor = DAG.getConstant(magics.Magic, dl, SVT);
More information about the llvm-commits
mailing list