Currently, LNICM pass does not support sinking instructions out of loop nest.
This patch enables LNICM to sink down as many instructions to the exit block of outermost loop as possible.
Details
- Reviewers
Whitney nikic bmahjour - Commits
- rGdd3eea65662a: [LICM] Support sinking in LNICM
Diff Detail
Event Timeline
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
12 | j not used? It would be better to use more “realistic” example. |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
12 | I don't think j need to be used. This test shows how LNICM handles a loop nest when it does sinking. If we use j here, an instruction using it would be neither hoisted or sunk, so I think it is redundant. |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
16 | Why wouldn't LICM sink s = abs(i); without y[i] = s;? |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
16 | LICM would hoist (not sink) s = abs(i); out of loop-j. |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
16 | how about ; for (int i = 0; i < 10; i++) { ; for (int j = 0; j < 10; j++) { ; t = sin(x); ; s = abs(i); ; } ; } ; return t + s; ? |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
16 | Oh, it is way better. I'll edit this test case. Thank you. |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
16 |
I ran the test case you suggested above, but LICM didn't do what we want... ; int i, j; ; for (i = 0; i < 10; i++) { ; for (j = 0; j < 10; j++) { ; } ; } ; t = sin(x); ; s = abs(i); ; return t + s; I should make another better test case. |
llvm/test/Transforms/LICM/lnicm-sink.ll | ||
---|---|---|
16 | I now see the point of y[i] = s;, let's see if you can make a better test case, if not, this is ok with me. |
llvm/include/llvm/Transforms/Utils/LoopUtils.h | ||
---|---|---|
157 | Please name the parameters of this function and add a comment about what each parameter means. Someone reading this declaration and its comments will see two Loop * being passed and cannot figure out what they are without going through its implementation. |
llvm/include/llvm/Transforms/Utils/LoopUtils.h | ||
---|---|---|
157 | Okay, I'll name the parameter Loop * = nullptr and add a comment to explain what two Loop * are. I don't think I need to name all parameters. |
Hi,
The following starts failing with this patch:
opt -passes='loop-mssa(lnicm)' -o /dev/null lnicm-crash.ll
I get
While deleting: i40 % Use still stuck around after Def is destroyed: %v_299.017 = phi i40 [ <badref>, %for.body1143 ] opt: ../lib/IR/Value.cpp:103: llvm::Value::~Value(): Assertion `materialized_use_empty() && "Uses remain when a value is destroyed!"' failed.
It looks like @uabelho may found another crash in sinkRegionForLoopNest https://github.com/llvm/llvm-project/issues/52688. Please take a look.
Please name the parameters of this function and add a comment about what each parameter means. Someone reading this declaration and its comments will see two Loop * being passed and cannot figure out what they are without going through its implementation.