From a09b5a0cfcbd7a1e7239f36c1cfd815c3ed19220 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sun, 22 Jan 2023 21:29:07 +0300 Subject: [PATCH] [NFC][SCEV] Reflow `GetMinTrailingZerosImpl()` into an exhaustive switch --- llvm/lib/Analysis/ScalarEvolution.cpp | 53 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 9025b90..c7066a3 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6314,31 +6314,32 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) { } uint32_t ScalarEvolution::GetMinTrailingZerosImpl(const SCEV *S) { - if (const SCEVConstant *C = dyn_cast(S)) - return C->getAPInt().countTrailingZeros(); - - if (const SCEVPtrToIntExpr *I = dyn_cast(S)) - return GetMinTrailingZeros(I->getOperand()); - - if (const SCEVTruncateExpr *T = dyn_cast(S)) + switch (S->getSCEVType()) { + case scConstant: + return cast(S)->getAPInt().countTrailingZeros(); + case scTruncate: { + const SCEVTruncateExpr *T = cast(S); return std::min(GetMinTrailingZeros(T->getOperand()), (uint32_t)getTypeSizeInBits(T->getType())); - - if (const SCEVZeroExtendExpr *E = dyn_cast(S)) { + } + case scZeroExtend: { + const SCEVZeroExtendExpr *E = cast(S); uint32_t OpRes = GetMinTrailingZeros(E->getOperand()); return OpRes == getTypeSizeInBits(E->getOperand()->getType()) ? getTypeSizeInBits(E->getType()) : OpRes; } - - if (const SCEVSignExtendExpr *E = dyn_cast(S)) { + case scSignExtend: { + const SCEVSignExtendExpr *E = cast(S); uint32_t OpRes = GetMinTrailingZeros(E->getOperand()); return OpRes == getTypeSizeInBits(E->getOperand()->getType()) ? getTypeSizeInBits(E->getType()) : OpRes; } - - if (const SCEVMulExpr *M = dyn_cast(S)) { + case scPtrToInt: + return GetMinTrailingZeros(cast(S)->getOperand()); + case scMulExpr: { + const SCEVMulExpr *M = cast(S); // The result is the sum of all operands results. uint32_t SumOpRes = GetMinTrailingZeros(M->getOperand(0)); uint32_t BitWidth = getTypeSizeInBits(M->getType()); @@ -6348,9 +6349,15 @@ uint32_t ScalarEvolution::GetMinTrailingZerosImpl(const SCEV *S) { std::min(SumOpRes + GetMinTrailingZeros(M->getOperand(i)), BitWidth); return SumOpRes; } - - if (isa(S) || isa(S) || isa(S) || - isa(S)) { + case scUDivExpr: + return 0; + case scAddExpr: + case scAddRecExpr: + case scUMaxExpr: + case scSMaxExpr: + case scUMinExpr: + case scSMinExpr: + case scSequentialUMinExpr: { // The result is the min of all operands results. const SCEVNAryExpr *M = cast(S); uint32_t MinOpRes = GetMinTrailingZeros(M->getOperand(0)); @@ -6358,15 +6365,17 @@ uint32_t ScalarEvolution::GetMinTrailingZerosImpl(const SCEV *S) { MinOpRes = std::min(MinOpRes, GetMinTrailingZeros(M->getOperand(I))); return MinOpRes; } - - if (const SCEVUnknown *U = dyn_cast(S)) { + case scUnknown: { + const SCEVUnknown *U = cast(S); // For a SCEVUnknown, ask ValueTracking. - KnownBits Known = computeKnownBits(U->getValue(), getDataLayout(), 0, &AC, nullptr, &DT); + KnownBits Known = + computeKnownBits(U->getValue(), getDataLayout(), 0, &AC, nullptr, &DT); return Known.countMinTrailingZeros(); } - - // SCEVUDivExpr - return 0; + case scCouldNotCompute: + llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!"); + } + llvm_unreachable("Unknown SCEV kind!"); } uint32_t ScalarEvolution::GetMinTrailingZeros(const SCEV *S) { -- 2.7.4