[llvm] [InstCombine] Fold `switch(rol(x, C1)) case C2:` to `switch(x) case rol(C2, -C1):` (PR #86307)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 10:26:26 PDT 2024
================
@@ -3645,6 +3645,16 @@ Instruction *InstCombinerImpl::visitSwitchInst(SwitchInst &SI) {
}
}
+ // Fold 'switch(rol(x, C1)) case C2:' to 'switch(x) case rol(C2, -C1):'
+ if (match(Cond,
+ m_FShl(m_Value(Op0), m_Deferred(Op0), m_ConstantInt(ShiftAmt)))) {
+ for (auto &Case : SI.cases()) {
+ const APInt NewCase = Case.getCaseValue()->getValue().rotr(ShiftAmt);
+ Case.setValue(ConstantInt::get(SI.getContext(), NewCase));
+ }
+ return replaceOperand(SI, 0, Op0);
+ }
----------------
dtcxzyw wrote:
> Bit weird to handle `rol` but not `ror`...
fshr with constant shamt should be canonicalized into fshl.
Godbolt: https://godbolt.org/z/x81a837s1
https://github.com/llvm/llvm-project/pull/86307
More information about the llvm-commits
mailing list