Skip to content

[SPIR-V][NFC] More efficient getPaddedLen #105823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

bwlodarcz
Copy link
Contributor

Quick fix with small performance improvement for getPaddedLen function.

Quick fix with small performance improvement for getPaddedLen function.
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

@llvm/pr-subscribers-backend-spir-v

Author: None (bwlodarcz)

Changes

Quick fix with small performance improvement for getPaddedLen function.


Full diff: https://github.com/llvm/llvm-project/pull/105823.diff

1 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVUtils.cpp (+1-2)
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) {

Copy link

github-actions bot commented Aug 23, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@bwlodarcz
Copy link
Contributor Author

@michalpaszkowski @VyacheslavLevytskyy @Keenuts Please review this quick fix. Thank you.

@michalpaszkowski michalpaszkowski merged commit 4ffb747 into llvm:main Sep 26, 2024
7 of 9 checks passed
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Sep 27, 2024
Quick fix with small performance improvement for getPaddedLen function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants