Dead Code Elimination and undef values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dead Code Elimination and undef values

Cristianno Martins
Hello there,

I'm writing a transformation pass for LLVM, and I hoped to use dce to clean up the resulting code after my pass. I just have some questions about LLVM's dce implementation.

Well, my transformation is a function pass, and, after the changes are made, some instructions are not needed anymore. In order to easily get rid of those instructions, I'm setting all their uses to UndefValue. This is necessary because some of the instructions I want to erase are inside loops, and, therefore, there might be a circular dependence between the instruction I want to delete and a PHINode, for example, when both of them are not useful anymore.

Ok, the problem is: I've always had explicitly invoked opt enabling, at least, -dce -adce -globaldce and -die, and I'm still getting a resultant code with some instructions like:

store i8 undef, i8* %out.1107, align 1, !tbaa !1

and

%storemerge = phi i8 [ %conv46, %if.else ], [ %call, %if.then ],
where %storemerge has no uses.

So, is there any other dce variant I should be enabling for opt? Better yet, is this the correct behavior for all the dce variants I enabled in opt?

Thanks,

--
Cristianno Martins
PhD Student of Computer Science
University of Campinas
[hidden email]
[hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Dead Code Elimination and undef values

Duncan Sands
Hi Cristianno,

On 01/06/13 01:49, Cristianno Martins wrote:

> Hello there,
>
> I'm writing a transformation pass for LLVM, and I hoped to use dce to clean up
> the resulting code after my pass. I just have some questions about LLVM's dce
> implementation.
>
> Well, my transformation is a function pass, and, after the changes are made,
> some instructions are not needed anymore. In order to easily get rid of those
> instructions, I'm setting all their uses to UndefValue. This is necessary
> because some of the instructions I want to erase are inside loops, and,
> therefore, there might be a circular dependence between the instruction I want
> to delete and a PHINode, for example, when both of them are not useful anymore.
>
> Ok, the problem is: I've always had explicitly invoked opt enabling, at least,
> -dce -adce -globaldce and -die, and I'm still getting a resultant code with some
> instructions like:
>
> store i8 undef, i8* %out.1107, align 1, !tbaa !1
>
> and
>
> %storemerge = phi i8 [ %conv46, %if.else ], [ %call, %if.then ],
> where %storemerge has no uses.
>
> So, is there any other dce variant I should be enabling for opt? Better yet, is
> this the correct behavior for all the dce variants I enabled in opt?

try running the instcombine pass too.  I'm surprised that dce didn't get the phi
node though, want to open a bugreport about that?

Ciao, Duncan.

>
> Thanks,
>
> --
> Cristianno Martins
> PhD Student of Computer Science
> University of Campinas
> [hidden email] <mailto:[hidden email]>
> <mailto:[hidden email]>
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Dead Code Elimination and undef values

Cristianno Martins
Hi Duncan,

Sorry for my late reply.

First, since I had already the information about which instructions should be deleted, I ended up writing a function that just erase all the useless instructions. Besides that, I actually think the problem with dce was being cause by my pass: I forgot to return "true" at the end of it, and I guess the PassManager was not calling dce after it because my pass was telling the PassManager the code was not being modified. If this is the case, there is no bug to report, right?

Either way, thank you for your reply =),


--
Cristianno Martins
PhD Student of Computer Science
University of Campinas
[hidden email]
[hidden email]


On Fri, May 31, 2013 at 10:26 PM, Duncan Sands <[hidden email]> wrote:
Hi Cristianno,


On 01/06/13 01:49, Cristianno Martins wrote:
Hello there,

I'm writing a transformation pass for LLVM, and I hoped to use dce to clean up
the resulting code after my pass. I just have some questions about LLVM's dce
implementation.

Well, my transformation is a function pass, and, after the changes are made,
some instructions are not needed anymore. In order to easily get rid of those
instructions, I'm setting all their uses to UndefValue. This is necessary
because some of the instructions I want to erase are inside loops, and,
therefore, there might be a circular dependence between the instruction I want
to delete and a PHINode, for example, when both of them are not useful anymore.

Ok, the problem is: I've always had explicitly invoked opt enabling, at least,
-dce -adce -globaldce and -die, and I'm still getting a resultant code with some
instructions like:

store i8 undef, i8* %out.1107, align 1, !tbaa !1

and

%storemerge = phi i8 [ %conv46, %if.else ], [ %call, %if.then ],
where %storemerge has no uses.

So, is there any other dce variant I should be enabling for opt? Better yet, is
this the correct behavior for all the dce variants I enabled in opt?

try running the instcombine pass too.  I'm surprised that dce didn't get the phi
node though, want to open a bugreport about that?

Ciao, Duncan.


Thanks,

--
Cristianno Martins
PhD Student of Computer Science
University of Campinas
[hidden email] <mailto:[hidden email]>
<mailto:[hidden email]>


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev