[all-commits] [llvm/llvm-project] 387703: [LoopIdiom] Select llvm.experimental.memset.patter...

Alex Bradbury via All-commits all-commits at lists.llvm.org
Wed Jul 9 05:48:37 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3877039fd1d09f87f13fdf64c544eafcfc09c650
      https://github.com/llvm/llvm-project/commit/3877039fd1d09f87f13fdf64c544eafcfc09c650
  Author: Alex Bradbury <asb at igalia.com>
  Date:   2025-07-09 (Wed, 09 Jul 2025)

  Changed paths:
    M llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
    A llvm/test/Transforms/LoopIdiom/RISCV/memset-pattern.ll
    M llvm/test/Transforms/LoopIdiom/basic.ll
    M llvm/test/Transforms/LoopIdiom/memset-pattern-tbaa.ll
    M llvm/test/Transforms/LoopIdiom/struct_pattern.ll
    M llvm/test/Transforms/LoopIdiom/unroll-custom-dl.ll
    M llvm/test/Transforms/LoopIdiom/unroll.ll

  Log Message:
  -----------
  [LoopIdiom] Select llvm.experimental.memset.pattern intrinsic rather than memset_pattern16 libcall (#126736)

In order to keep the change as incremental as possible, this only
introduces the memset.pattern intrinsic in cases where memset_pattern16
would have been used. Future patches can enable it on targets that don't
have the intrinsic, and select it in cases where the libcall isn't
directly usable. As the memset.pattern intrinsic takes the number of
times to store the pattern as an argument unlike memset_pattern16 which
takes the number of bytes to write, we no longer try to form an i128
pattern.

Special care is taken for cases where multiple stores in the same loop
iteration were combined to form a single pattern. For such cases, we
inherit the limitation that loops such as the following are supported:

```
for (unsigned i = 0; i < 2 * n; i += 2) {
  f[i] = 2;
  f[i+1] = 2;
}
```

But the following doesn't result in a memset.pattern (even though it
could be, by forming an appropriate pattern):
```
for (unsigned i = 0; i < 2 * n; i += 2) {
  f[i] = 2;
  f[i+1] = 3;
}
```

Addressing this existing deficiency is left for a follow-up due to a
desire not to change too much at once (i.e. to target equivalence to the
current codegen).

A command line option is introduced to force the selection of the
intrinsic even in cases it wouldn't be (i.e. in cases where the libcall
wouldn't have been selected). This is intended as a transitionary option
for testing and experimentation, to be removed at a later point.

The only platforms this should impact are those that have the memset_pattern16 libcall (Apple platforms). Testing performed to check for no unexpected codegen changes is described here https://github.com/llvm/llvm-project/pull/126736#issuecomment-3005097468



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list