[all-commits] [llvm/llvm-project] 72ffaa: [IR][TRE] Support associative intrinsics (#74226)
Joshua Cao via All-commits
all-commits at lists.llvm.org
Mon Dec 4 22:36:12 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 72ffaa915623e337abb5c689b5087d7e1d4477ae
https://github.com/llvm/llvm-project/commit/72ffaa915623e337abb5c689b5087d7e1d4477ae
Author: Joshua Cao <cao.joshua at yahoo.com>
Date: 2023-12-04 (Mon, 04 Dec 2023)
Changed paths:
M llvm/include/llvm/IR/Constants.h
M llvm/include/llvm/IR/IntrinsicInst.h
M llvm/lib/IR/Constants.cpp
M llvm/lib/IR/Instruction.cpp
M llvm/lib/Transforms/Scalar/Reassociate.cpp
M llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
M llvm/test/Transforms/TailCallElim/accum_recursion.ll
M llvm/test/Transforms/TailCallElim/tre-minmax-intrinsic.ll
Log Message:
-----------
[IR][TRE] Support associative intrinsics (#74226)
There is support for intrinsics in Instruction::isCommunative, but there
is no equivalent implementation for isAssociative. This patch builds
support for associative intrinsics with TRE as an application. TRE can
now have associative intrinsics as an accumulator. For example:
```
struct Node {
Node *next;
unsigned val;
}
unsigned maxval(struct Node *n) {
if (!n) return 0;
return std::max(n->val, maxval(n->next));
}
```
Can be transformed into:
```
unsigned maxval(struct Node *n) {
struct Node *head = n;
unsigned max = 0; // Identity of unsigned std::max
while (true) {
if (!head) return max;
max = std::max(max, head->val);
head = head->next;
}
return max;
}
```
This example results in about 5x speedup in local runs.
We conservatively only consider min/max and as associative for this
patch to limit testing scope. There are probably other intrinsics that
could be considered associative. There are a few consumers of
isAssociative() that could be impacted. Testing has only required to
Reassociate pass be updated.
More information about the All-commits
mailing list