# [TRE] Allow elimination when the returned value is non-constant2bf3fe9b6dedActions

Authored by laytonio on May 27 2020, 4:54 PM.

# Description

[TRE] Allow elimination when the returned value is non-constant

Currently we can only eliminate call return pairs that either return the
result of the call or a dynamic constant. This patch removes that
limitation.

Differential Revision: https://reviews.llvm.org/D79660

# Details

Committed
 efriedma May 27 2020, 4:55 PM
Differential Revision
D79660: [TRE] Allow elimination when the returned value is non-constant
Parents
rG7392bbc3014c: AMDGPU/GlobalISel: Fixed insert element for non-standard vectors
Branches
Unknown
Tags
Unknown

### Event Timeline

xbolva00 added a subscriber: xbolva00.EditedMay 27 2020, 5:26 PM

Hello,

since you have improved this pass, can you please take a look at this PR:
https://bugs.llvm.org/show_bug.cgi?id=36918

?

@laytonio

I don't currently have a bugzilla account but I will try to sign up tomorrow so I can reply to this. I'll give a quick run down below though.

```int factorial(int n)
{
if (n <= 0) return 1;
return n * factorial(n - 1);
}```

This call is currently getting eliminated, and the original bug seems to be related to the vectorization decision not the call elimination which is valid.

```unsigned almost_factorial(unsigned n)
{
if (n <= 0) return 1;
return 2 *  almost_factorial(n - 1);
}```

This seems to be because the multiplication by 2 is getting converted to a shift which is confusing things for some reason. If you change it to 3 or manually edit the IR to replace the shift with a multiplication this gets vectorized similar to the first example. I will look into why the shift isn't working.

```unsigned almost_factorial(int A[10], unsigned n)
{
if (n <= 0) return A[0];
return A[n] + almost_factorial(A, n - 1);
}```

I actually have already been working on a patch to eliminate calls in cases like this and will post it for review tomorrow if I have time.

Lucas added a subscriber: Lucas.May 31 2020, 5:05 AM
Lucas removed a subscriber: Lucas.