[llvm] d1688e9 - [llvm] Use std::gcd (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 27 23:54:46 PDT 2022
Author: Kazu Hirata
Date: 2022-08-27T23:54:29-07:00
New Revision: d1688e9ddfeda5043913c67eaf2ef28f9574a33b
URL: https://github.com/llvm/llvm-project/commit/d1688e9ddfeda5043913c67eaf2ef28f9574a33b
DIFF: https://github.com/llvm/llvm-project/commit/d1688e9ddfeda5043913c67eaf2ef28f9574a33b.diff
LOG: [llvm] Use std::gcd (NFC)
This patch replaces calls to greatestCommonDivisor with std::gcd where
both arguments are known to be of unsigned. This means that
std::common_type_t of the two argument types should just be the wider
one of the two.
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/Utils.cpp
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 16b0d4753d284..15c21fe48c43e 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -895,8 +895,8 @@ LLT llvm::getLCMType(LLT OrigTy, LLT TargetTy) {
const LLT TargetElt = TargetTy.getElementType();
if (OrigElt.getSizeInBits() == TargetElt.getSizeInBits()) {
- int GCDElts = greatestCommonDivisor(OrigTy.getNumElements(),
- TargetTy.getNumElements());
+ int GCDElts =
+ std::gcd(OrigTy.getNumElements(), TargetTy.getNumElements());
// Prefer the original element type.
ElementCount Mul = OrigTy.getElementCount() * TargetTy.getNumElements();
return LLT::vector(Mul.divideCoefficientBy(GCDElts),
@@ -954,8 +954,7 @@ LLT llvm::getGCDType(LLT OrigTy, LLT TargetTy) {
if (TargetTy.isVector()) {
LLT TargetElt = TargetTy.getElementType();
if (OrigElt.getSizeInBits() == TargetElt.getSizeInBits()) {
- int GCD = greatestCommonDivisor(OrigTy.getNumElements(),
- TargetTy.getNumElements());
+ int GCD = std::gcd(OrigTy.getNumElements(), TargetTy.getNumElements());
return LLT::scalarOrVector(ElementCount::getFixed(GCD), OrigElt);
}
} else {
@@ -964,7 +963,7 @@ LLT llvm::getGCDType(LLT OrigTy, LLT TargetTy) {
return OrigElt;
}
- unsigned GCD = greatestCommonDivisor(OrigSize, TargetSize);
+ unsigned GCD = std::gcd(OrigSize, TargetSize);
if (GCD == OrigElt.getSizeInBits())
return OrigElt;
@@ -982,7 +981,7 @@ LLT llvm::getGCDType(LLT OrigTy, LLT TargetTy) {
return OrigTy;
}
- unsigned GCD = greatestCommonDivisor(OrigSize, TargetSize);
+ unsigned GCD = std::gcd(OrigSize, TargetSize);
return LLT::scalar(GCD);
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
index 55f98519b69f5..ffdb8fd1a6c55 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -27,6 +27,8 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TypeSize.h"
#include "llvm/Support/raw_ostream.h"
+#include <numeric>
+
using namespace llvm;
#define DEBUG_TYPE "legalize-types"
@@ -4955,7 +4957,7 @@ SDValue DAGTypeLegalizer::WidenVecRes_EXTRACT_SUBVECTOR(SDNode *N) {
// nxv2i64 extract_subvector(nxv16i64, 8)
// nxv2i64 extract_subvector(nxv16i64, 10)
// undef)
- unsigned GCD = greatestCommonDivisor(VTNumElts, WidenNumElts);
+ unsigned GCD = std::gcd(VTNumElts, WidenNumElts);
assert((IdxVal % GCD) == 0 && "Expected Idx to be a multiple of the broken "
"down type's element count");
EVT PartVT = EVT::getVectorVT(*DAG.getContext(), EltVT,
@@ -6376,7 +6378,7 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) {
unsigned WideElts = WideVT.getVectorMinNumElements();
if (WideVT.isScalableVector()) {
- unsigned GCD = greatestCommonDivisor(OrigElts, WideElts);
+ unsigned GCD = std::gcd(OrigElts, WideElts);
EVT SplatVT = EVT::getVectorVT(*DAG.getContext(), ElemVT,
ElementCount::getScalable(GCD));
SDValue SplatNeutral = DAG.getSplatVector(SplatVT, dl, NeutralElem);
@@ -6413,7 +6415,7 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE_SEQ(SDNode *N) {
unsigned WideElts = WideVT.getVectorMinNumElements();
if (WideVT.isScalableVector()) {
- unsigned GCD = greatestCommonDivisor(OrigElts, WideElts);
+ unsigned GCD = std::gcd(OrigElts, WideElts);
EVT SplatVT = EVT::getVectorVT(*DAG.getContext(), ElemVT,
ElementCount::getScalable(GCD));
SDValue SplatNeutral = DAG.getSplatVector(SplatVT, dl, NeutralElem);
diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
index 53812d7552a90..306c485b87913 100644
--- a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
@@ -98,6 +98,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Pass.h"
+#include <numeric>
#include <queue>
#define DEBUG_TYPE "nvptx-lower-args"
@@ -303,7 +304,7 @@ static void adjustByValArgAlignment(Argument *Arg, Value *ArgInParamAS,
}
for (Load &CurLoad : Loads) {
- Align NewLoadAlign(greatestCommonDivisor(NewArgAlign, CurLoad.Offset));
+ Align NewLoadAlign(std::gcd(NewArgAlign, CurLoad.Offset));
Align CurLoadAlign(CurLoad.Inst->getAlign());
CurLoad.Inst->setAlignment(std::max(NewLoadAlign, CurLoadAlign));
}
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index cf64ff5885f2f..26720829756a5 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -60,6 +60,7 @@
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <cassert>
+#include <numeric>
using namespace llvm;
@@ -4427,8 +4428,7 @@ static unsigned getKnownAlignForUse(Attributor &A, AAAlign &QueryingAA,
// So we can say that the maximum power of two which is a divisor of
// gcd(Offset, Alignment) is an alignment.
- uint32_t gcd =
- greatestCommonDivisor(uint32_t(abs((int32_t)Offset)), Alignment);
+ uint32_t gcd = std::gcd(uint32_t(abs((int32_t)Offset)), Alignment);
Alignment = llvm::PowerOf2Floor(gcd);
}
}
@@ -4563,8 +4563,8 @@ struct AAAlignFloating : AAAlignImpl {
// So we can say that the maximum power of two which is a divisor of
// gcd(Offset, Alignment) is an alignment.
- uint32_t gcd = greatestCommonDivisor(uint32_t(abs((int32_t)Offset)),
- uint32_t(PA.value()));
+ uint32_t gcd =
+ std::gcd(uint32_t(abs((int32_t)Offset)), uint32_t(PA.value()));
Alignment = llvm::PowerOf2Floor(gcd);
} else {
Alignment = V.getPointerAlignment(DL).value();
More information about the llvm-commits
mailing list