[LLVMdev] Optimisation of select/cmp/br

Pete Calvert prc33 at cam.ac.uk
Thu Feb 6 06:48:59 PST 2014


On 2014-02-05 23:32, Rafael EspĂ­ndola wrote:
> On 4 February 2014 23:37, Pete Calvert <prc33 at cam.ac.uk> wrote:
>> Hi,
>> 
>> Is there anyway I can coerce LLVM into performing the following
>> transformation?
>> 
>>   %1 = icmp eq i32 %flag, 1
>>   %2 = select i1 %1, %foo* %data, %foo* null
>>   %3 = icmp eq %foo* %2, null
>>   br i1 %3, label %failure, label %success
>> 
> 
> It seems something that GVN should be able to handle if expressed with
> branches instead of select. Unfortunately it currently doesn't :-(
> 
> It is a long project, but one way to fix this might be to extend
> (rewrite?) GVN PRE (pr13307, pr10254) and then make GVN handle selects
> too (on way to fix pr13590 and hopefully your example).

I'm not at all familiar with the LLVM internals (just with the Ocaml 
bindings for generating IR), but could try and help out with this if 
there was agreement on how it needs doing / someone gave me a pointer in 
the right direction. I guess this case is the most tricky of the ones 
you listed since it relies on knowledge that %data is not null. I've 
filed this as a bug (#18754).

Pete




More information about the llvm-dev mailing list