[llvm] [InstCombine] Pull vector reverse through intrinsics (PR #146384)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 11:02:41 PDT 2025
================
@@ -1456,6 +1456,45 @@ InstCombinerImpl::foldShuffledIntrinsicOperands(IntrinsicInst *II) {
return new ShuffleVectorInst(NewIntrinsic, Mask);
}
+/// If all arguments of the intrinsic are reverses, try to pull the reverse
+/// after the intrinsic.
+Value *InstCombinerImpl::foldReversedIntrinsicOperands(IntrinsicInst *II) {
+ if (!isTriviallyVectorizable(II->getIntrinsicID()) ||
+ !II->getCalledFunction()->isSpeculatable())
+ return nullptr;
+
+ // At least 1 operand must be a reverse with 1 use because we are creating 2
+ // instructions.
+ if (none_of(II->args(), [](Value *V) {
+ return match(V, m_OneUse(m_VecReverse(m_Value())));
+ }))
+ return nullptr;
+
+ Value *X;
+ Constant *C;
+ SmallVector<Value *> NewArgs;
+ for (Use &Arg : II->args()) {
+ if (isVectorIntrinsicWithScalarOpAtArg(II->getIntrinsicID(),
+ Arg.getOperandNo(), nullptr))
+ NewArgs.push_back(Arg);
+ else if (match(&Arg, m_VecReverse(m_Value(X))))
+ NewArgs.push_back(X);
+ else if (Value *Splat = getSplatValue(Arg))
----------------
preames wrote:
Hm, since we're inserting a new splat, do we need the existing one to be one-use? You do need to insert a new one instead of reusing because of possible undef/poison lanes.
https://github.com/llvm/llvm-project/pull/146384
More information about the llvm-commits
mailing list