[llvm] [CodeGen] Remove redundant vector checks (PR #99524)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 11:48:26 PDT 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/99524
>From 0f54cfcc52fbb9a16905b4870cb30fe26d9d40ec Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Thu, 18 Jul 2024 12:23:13 -0400
Subject: [PATCH] [CodeGen] Remove redundant vector checks
It turns out we can safely use DAG.computeKnownBits(N0).countMinLeadingZeros() with constant legal vectors, so remove the check for it.
---
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | 4 +++-
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 13 +++----------
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index dfc3d73e322b8..a510f40decb84 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -5180,7 +5180,9 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType();
unsigned KnownLeadingZeros =
- KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
+ (!MI.getFlag(MachineInstr::MIFlag::IsExact) && KB)
+ ? KB->getKnownBits(LHS).countMinLeadingZeros()
+ : 0;
auto &MIB = Builder;
bool UseSRL = false;
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index c3a20b5044c5f..140c97ccd90ba 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;
@@ -6510,7 +6502,8 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
MagicFactor = NPQFactor = DAG.getUNDEF(SVT);
} else {
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