[LLVMdev] Eliminating PHI with Identical Inputs

Duncan Sands baldrick at free.fr
Tue Jul 30 07:46:15 PDT 2013


Hi John,

On 30/07/13 16:12, John Criswell wrote:
> Dear All,
>
> Is there a pass (or set of passes) that will replace a phi whose input operands
> all compute the same value with an instruction that computes that value?  In
> other words, something that will convert:
>
> define internal i32 @function(i32 %x) {
> ...
> bb1:
> %y = add %x, 10
> ...
> bb2:
> %z = add %x, 10
> ...
> bb3:
> %phi = [bb1, %y], [bb2, %z]
>
> into
>
> define internal i32 @function(i32 %x) {
> ...
> bb1:
> ...
> bb2:
> ...
> bb3:
> %phi = add %x, 10

yes, GVN should replace %y and %z with the same register, giving something like

  %same = add %x, 10
...
  bb1:
  ...
  bb2:
  ...
  bb3:
  %phi = [bb1, %same], [bb2, %same]

at which point the instcombine pass should zap the phi, though maybe GVN will
get it already.

Ciao, Duncan.



More information about the llvm-dev mailing list