[llvm] [SPIR-V][NFC] More efficient getPaddedLen (PR #105823)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 05:44:14 PDT 2024


https://github.com/bwlodarcz updated https://github.com/llvm/llvm-project/pull/105823

>From c756958fa58e5b75cab2601cc6d4577ec8ab0152 Mon Sep 17 00:00:00 2001
From: "Wlodarczyk, Bertrand" <bertrand.wlodarczyk at intel.com>
Date: Fri, 23 Aug 2024 14:34:16 +0200
Subject: [PATCH 1/2] [SPIR-V][NFC] More efficient getPaddedLen

Quick fix with small performance improvement for getPaddedLen function.
---
 llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 927683ad7e32be..68f166d0bef4ea 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -44,8 +44,7 @@ static uint32_t convertCharsToWord(const StringRef &Str, unsigned i) {
 
 // Get length including padding and null terminator.
 static size_t getPaddedLen(const StringRef &Str) {
-  const size_t Len = Str.size() + 1;
-  return (Len % 4 == 0) ? Len : Len + (4 - (Len % 4));
+  return Str.size() + 4 & ~3;
 }
 
 void addStringImm(const StringRef &Str, MCInst &Inst) {

>From 48f55b5a3dbf3d04ec64eb9847f2e58a1340e35b Mon Sep 17 00:00:00 2001
From: "Wlodarczyk, Bertrand" <bertrand.wlodarczyk at intel.com>
Date: Fri, 23 Aug 2024 14:43:58 +0200
Subject: [PATCH 2/2] Format fix

---
 llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 68f166d0bef4ea..ab1365e40d6f8a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -43,9 +43,7 @@ static uint32_t convertCharsToWord(const StringRef &Str, unsigned i) {
 }
 
 // Get length including padding and null terminator.
-static size_t getPaddedLen(const StringRef &Str) {
-  return Str.size() + 4 & ~3;
-}
+static size_t getPaddedLen(const StringRef &Str) { return Str.size() + 4 & ~3; }
 
 void addStringImm(const StringRef &Str, MCInst &Inst) {
   const size_t PaddedLen = getPaddedLen(Str);



More information about the llvm-commits mailing list