[llvm] [LoopIdiom] Do not emit wcslen for underaligned wide loads (PR #216080)
Ömer Sinan Ağacan via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 15 12:52:44 PDT 2026
================
@@ -2107,10 +2107,20 @@ class StrlenVerifier {
return false;
if (OpWidth != 8 && OpWidth != 16 && OpWidth != 32)
return false;
- if (OpWidth >= 16)
+ if (OpWidth >= 16) {
if (OpWidth != WcharSize * 8)
return false;
+ // wcslen requires a pointer aligned to wchar_t. Loops that load
+ // wchar_t-sized values at weaker alignment (e.g. memcpy from a byte
+ // buffer) must not be rewritten as wcslen.
+ Align RequiredAlign(WcharSize);
----------------
osa1 wrote:
I don't understand why you're initializing an alignment value as the size?
`getABITypeAlign` may be the method we want to use here: https://github.com/llvm/llvm-project/blob/e5174fe683e882f6bbd2ef023c9c9e293b273a98/llvm/include/llvm/IR/DataLayout.h#L630
https://github.com/llvm/llvm-project/pull/216080
More information about the llvm-commits
mailing list