[llvm] [WebAssembly] Add support for memcmp expansion (PR #148298)

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 16 10:45:11 PDT 2025


================
@@ -141,6 +141,16 @@ InstructionCost WebAssemblyTTIImpl::getCastInstrCost(
   return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
 }
 
+WebAssemblyTTIImpl::TTI::MemCmpExpansionOptions
+WebAssemblyTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
+  TTI::MemCmpExpansionOptions Options;
----------------
dschuff wrote:

p2align=0 means that the engine can't assume any particular alignment*, so it should always be safe.  But if we do know the alignment from LLVM then it's good to put it into the output. In LLVM IR you can get alignment from several sources, e.g. directly from globals, alignment attributes on pointer parameters, alloca instructions, and more. You can also find examples of handling alignment in SelectionDAG and backend code.

It looks like in this case it's generating p2align=0 which should always be conservatively ok. And since this PR doesn't really affect the actual codegen I think it's fine. It might be the case that it already handles alignment, e.g. in code where we had more alignment info in the IR, it would just work.

*(Technically the engine can never make hard alignment assumptions because the alignment field doesn't actually have any semantics, so even loads that aren't actually sufficiently aligned still need to succeed, but they might be very slow)

https://github.com/llvm/llvm-project/pull/148298


More information about the llvm-commits mailing list