llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LoopDelete] The useless code in the loop should have been removed, but it wasn't

Open LiqinWeng opened this issue 3 years ago • 4 comments

Test Case:

int test()
{
    long I;
    long A[320] = {1};
    long B[320] = {2};
    long N7 = 320;
    for (I = 0; I < N7; I++)
    {
        A[I] = A[I] + B[I];
        B[I] = A[I] - B[I];
    }
   return 0;

The above code is actually useless code in the loop and should be deleted. It has not been deleted yet.

LiqinWeng avatar Nov 10 '23 07:11 LiqinWeng

@fhahn

LiqinWeng avatar Nov 10 '23 07:11 LiqinWeng

@LiqinWeng Is there any particular reason you closed this issue? LLVM should be able to remove the loop, but doesn't at the moment, unless the loop is unrolled: https://clang.godbolt.org/z/zhar8fYEh

The underlying reason is that memory optimizations (in particular DeadStoreElimination) aren't really aware of loops.

fhahn avatar Nov 11 '23 10:11 fhahn

The underlying reason is that memory optimizations (in particular DeadStoreElimination) aren't really aware of loops.

Sorry, I accidentally closed the issue. I can try to solve this problem on DeadStoreElimination

LiqinWeng avatar Nov 11 '23 10:11 LiqinWeng

For reference, here are some related issues: #56291, #45803, #45805

fhahn avatar Nov 11 '23 10:11 fhahn