[llvm] [InstCombine] Rotate transformation port from SelectionDAG to InstCombine (PR #160628)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 26 06:19:22 PDT 2025
================
@@ -2405,6 +2405,23 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
matchBSwapOrBitReverse(*II, /*MatchBSwaps*/ true,
/*MatchBitReversals*/ true))
return BitOp;
+
+ // R = fshl(X, X, C2)
+ // fshl(R, R, C1) --> fshl(X, X, (C1 + C2) % bitsize)
+ Value *InnerOp;
+ Constant *ShAmtInnerC;
+ if (match(Op0, m_FShl(m_Value(InnerOp), m_Deferred(InnerOp),
+ m_ImmConstant(ShAmtInnerC))) &&
+ Op0 == Op1) {
+ APInt Sum =
+ ShAmtC->getUniqueInteger() + ShAmtInnerC->getUniqueInteger();
----------------
dtcxzyw wrote:
> With this change, will this allow rotates with contant vectors such that something like this'll be allowed: <1, 2, 3> + <5, 6, 7> = <6, 8, 10>?
No. I mean, it is enough to just handle scalar + vector splat cases. See also https://llvm.org/docs/InstCombineContributorGuide.html#guidelines-for-reviewers. If you want to handle non-splat cases, use `ConstantFoldBinaryOpOperands` instead.
https://github.com/llvm/llvm-project/pull/160628
More information about the llvm-commits
mailing list