Skip to content

[InstCombine][SDAG] Add range attributes to shamts on fshl/fshr in matchFunnelShift #118200

@dtcxzyw

Description

@dtcxzyw

In https://reviews.llvm.org/D88783, we fold or(shl(a,x),lshr(b,sub(bw,x))) -> fshl(a,b,x) iff x < bw. This constraint on shamts is added to avoid redundant and x, 2^bw - 1 in the codegen. However, this may increase the complexity of ISel and produce inefficient code. See an example from https://github.com/cyyself/hwprobe/blob/master/ifunc_example/ror32.c: https://godbolt.org/z/fxEb1f65h.

To address this issue, we can add attribute range(iN 0, N) to the shamt in InstCombine. Then we use assertzext in SelectionDAGBuilder to eliminate unnecessary and insts.

Looking forward to your inputs.
cc @nikic @topperc @RKSimon @asb @preames @cyyself

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions