[llvm] [GISel] Fold bitreverse(shl/srl(bitreverse(x),y)) -> srl/shl(x,y) (PR #91355)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Tue May 7 09:43:00 PDT 2024
================
@@ -2016,6 +2016,36 @@ void CombinerHelper::applyCombineShlOfExtend(MachineInstr &MI,
MI.eraseFromParent();
}
+bool CombinerHelper::matchBitreverseShift(MachineInstr &MI,
+ BuildFnTy &MatchInfo) {
+ assert(MI.getOpcode() == TargetOpcode::G_BITREVERSE && "Expected BITREVERSE");
+ Register Dst = MI.getOperand(0).getReg();
+ Register Src = MI.getOperand(1).getReg();
+ Register Val, Amt;
+
+ // fold (bitreverse (shl (bitreverse x), y)) -> (lshr x, y)
+ if (mi_match(Src, MRI, m_GShl(m_GBitreverse(m_Reg(Val)), m_Reg(Amt))) &&
+ isLegalOrBeforeLegalizer(
+ {TargetOpcode::G_LSHR, {MRI.getType(Val), MRI.getType(Amt)}})) {
+ MatchInfo = [=](MachineIRBuilder &B) {
+ B.buildInstr(TargetOpcode::G_LSHR, {Dst}, {Val, Amt});
----------------
tschuett wrote:
```
B.buildShl(Dst, Val, Amt);
```
https://github.com/llvm/llvm-project/pull/91355
More information about the llvm-commits
mailing list