[llvm] [InstCombine] Fold vector.reduce.op(vector.reverse(X)) -> vector.reduce.op(X) (PR #91743)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 03:50:09 PDT 2024


================
@@ -1435,6 +1435,51 @@ static Instruction *foldBitOrderCrossLogicOp(Value *V,
   return nullptr;
 }
 
+Instruction *InstCombinerImpl::simplifyReductionOfShuffle(IntrinsicInst *II) {
+  Intrinsic::ID IID = II->getIntrinsicID();
+  bool CanBeReassociated = (IID != Intrinsic::vector_reduce_fadd &&
+                            IID != Intrinsic::vector_reduce_fmul) ||
+                           II->hasAllowReassoc();
+
+  if (!CanBeReassociated)
+    return nullptr;
+
+  const unsigned ArgIdx = (IID == Intrinsic::vector_reduce_fadd ||
+                           IID == Intrinsic::vector_reduce_fmul)
+                              ? 1
+                              : 0;
+  Value *Arg = II->getArgOperand(ArgIdx);
+  Value *V;
+
----------------
paulwalker-arm wrote:

Just a thought but perhaps this will be cleaner is you created something like `simplifyReductionOperand(Value* Op, bool CanReorderLanes)`?  So you'd end up with either:
```
if (auto *NewOp = simplifyReductionOperand(II->getArgOperand(0), true) {
  replaceUse(II->getOperandUse(0), NewOp);
  return nullptr;
}

if (auto *NewOp = simplifyReductionOperand(II->getArgOperand(1), II->hasAllowReassoc()) {
  replaceUse(II->getOperandUse(1), NewOp);
  return nullptr;
}
```

https://github.com/llvm/llvm-project/pull/91743


More information about the llvm-commits mailing list