| f46d5a3c | 12-Sep-2023 |
Alex Crichton <[email protected]> |
x64: Add support for some BMI2 instructions (#6976)
* x64: Add support for sarx, shlx, and shrx
These instructions are in the BMI2 instruction set and unconditionally used by LLVM for shifts which
x64: Add support for some BMI2 instructions (#6976)
* x64: Add support for sarx, shlx, and shrx
These instructions are in the BMI2 instruction set and unconditionally used by LLVM for shifts which don't have an immediate. They're equivalent to the sar, shl, and shr instructions except they use 3-operand form to lessen register allocation pressure.
Currently the integration here doesn't add new lowering but instead takes an AVX-like approach by updating the `x64_sar` and related helpers to use `sarx` instead if it fits. This means that the shift-a-value-stored-in-memory functionality of `sarx` and friends isn't exposed, so that's left for a future PR.
* x64: Add support for BMI2 `rorx` instruction
This is similar to `rol` and `ror` but requires an immediate argument and additionally has no constraints on registers.
* x64: Add support for BMI2 `bzhi` instruction
This commit adds support for the `bzhi` instruction which is part of BMI2. This instruction is used to zero out the upper bits of a register indexed by a register operand. Emission of this instruction is pattern-matched on CLIF which looks like this pattern. Equivalent code fed to LLVM will additionally generate the `bzhi` instruction.
Relative to the alternative lowerings x64 provides this gives a little bit more register freedom and additionally cuts down on a few instructions. Note that the raw functionality of `bzhi` can't be exposed though because the semantics of when the index is out-of-bounds doesn't match easily to a CLIF instruction, so usage of `bzhi` is always preceded by an `and` instruction. This matches LLVM as well, but LLVM probably has fancy logic where if it can prove the range of values of the index it probably elides the `and`.
* Pattern match more `x - 1` patterns
Looks like LLVM generates this as `x + (-1)` which is equivalent to `x - 1` so create a custom partial constructor to pattern match the possibilities of a decremented value.
* Add tests for BMI{1,2} coming from wasm
These are intended to serve as integration tests to ensure that even coming from wasm these instructions are all emitted.
show more ...
|