aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2023-08-12 10:56:53 -0700
committerCraig Topper <craig.topper@sifive.com>2023-08-12 11:14:51 -0700
commitee6befe26437034be84bf4785127b397afb9dfcb (patch)
treeb673acf415ad0c58cc1ca5c756a53355ad50908b /clang/lib/Sema/SemaChecking.cpp
parent4d0f1e328245d802665cf564eb0449b867ce8a48 (diff)
downloadllvm-ee6befe26437034be84bf4785127b397afb9dfcb.zip
llvm-ee6befe26437034be84bf4785127b397afb9dfcb.tar.gz
llvm-ee6befe26437034be84bf4785127b397afb9dfcb.tar.bz2
[RISCV] Rewrite CheckInvalidVLENandLMUL to avoid floating point.
This avoids needing an FP value to represent LMUL. Reviewed By: 4vtomat Differential Revision: https://reviews.llvm.org/D157651
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index dc45e8d..8c3abc2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4474,14 +4474,24 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, CallExpr *TheCall,
assert((EGW == 128 || EGW == 256) && "EGW can only be 128 or 256 bits");
// LMUL * VLEN >= EGW
- uint64_t ElemSize = Type->isRVVType(32, false) ? 32 : 64;
- uint64_t ElemCount = Type->isRVVType(1) ? 1 :
- Type->isRVVType(2) ? 2 :
- Type->isRVVType(4) ? 4 :
- Type->isRVVType(8) ? 8 :
- 16;
- float Lmul = (float)(ElemSize * ElemCount) / llvm::RISCV::RVVBitsPerBlock;
- uint64_t MinRequiredVLEN = std::max(EGW / Lmul, (float)ElemSize);
+ unsigned ElemSize = Type->isRVVType(32, false) ? 32 : 64;
+ unsigned MinElemCount = Type->isRVVType(1) ? 1
+ : Type->isRVVType(2) ? 2
+ : Type->isRVVType(4) ? 4
+ : Type->isRVVType(8) ? 8
+ : 16;
+
+ unsigned EGS = EGW / ElemSize;
+ // If EGS is less than or equal to the minimum number of elements, then the
+ // type is valid.
+ if (EGS <= MinElemCount)
+ return false;
+
+ // Otherwise, we need vscale to be at least EGS / MinElemCont.
+ assert(EGS % MinElemCount == 0);
+ unsigned VScaleFactor = EGS / MinElemCount;
+ // Vscale is VLEN/RVVBitsPerBlock.
+ unsigned MinRequiredVLEN = VScaleFactor * llvm::RISCV::RVVBitsPerBlock;
std::string RequiredExt = "zvl" + std::to_string(MinRequiredVLEN) + "b";
if (!TI.hasFeature(RequiredExt))
return S.Diag(TheCall->getBeginLoc(),