[llvm] [TRE] Add tests for intrinsic accumulators (PR #74226)

Joshua Cao via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 3 01:51:48 PST 2023


================
@@ -369,12 +369,25 @@ static bool canTransformAccumulatorRecursion(Instruction *I, CallInst *CI) {
   if (!I->isAssociative() || !I->isCommutative())
     return false;
 
-  assert(I->getNumOperands() == 2 &&
-         "Associative/commutative operations should have 2 args!");
+  Value *LHS;
+  Value *RHS;
+  if (I->isBinaryOp()) {
+    LHS = I->getOperand(0);
+    RHS = I->getOperand(1);
+  } else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
+    // Accumulators must have an identity.
+    if (!ConstantExpr::getIntrinsicIdentity(II->getIntrinsicID(), I->getType()))
+      return false;
+    // 0'th operand is the intrinsic function
----------------
caojoshua wrote:

So I got "lucky". This code checks that the accumulator instruction has the recursive call as one of the inputs. And if so, returns that we can accumulate. All my test cases had the call result as the RHS, which is `I->getOperand(1)`, so we return that accumulation is possible.

The later code transformations actually looks at the correct operands and makes the right transformation. I'll fix this and add some test cases for this.

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


More information about the llvm-commits mailing list