[PATCH] D140087: [X86] Replace (31/63 -/^ X) with (NOT X) and ignore (32/64 ^ X) when computing shift count

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 10:23:02 PST 2022


craig.topper added a comment.

In D140087#4008447 <https://reviews.llvm.org/D140087#4008447>, @goldstein.w.n wrote:

> @pengfei Somewhat unrelated so if this is not the right place the ask, can you let me know where is.
>
> I was looking to add a peephole to change something like:
>
>   ptr[x / 32] |= (1 << (x % 32))
>
> Currently codegen is something like:
>
>   mov    $0x1,%gpr1
>   shlx   %cnt,%gpr1,%mask
>   shr    $0x5,%cnt
>   or  %mask, (%ptr, %cnt, 4)
>
> And it could be as simple as:
>
>   bts %cnt, (%ptr)
>
> (other pattern with `bt{s|r|c}` could also be improved)
>
> I saw `one_bit_patterns` in `X86InstrCompiler` but don't see a way to extend
> the peephole s.t `addr` is a function of the inputs and not just one of the inputs.
>
> Any chance you could direct me as where I should look at add this type of
> peephole?

`bts %cnt, (%ptr)` is not modulo the shift amount by 32. It will add %cnt%32 to %ptr to calculate a new address. And its a 10 or 11 uop instruction.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140087/new/

https://reviews.llvm.org/D140087



More information about the llvm-commits mailing list