[PATCH] D32252: [GVN] Add phi-translate for scalarpre as a temporary solution

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 16:04:37 PDT 2017


dberlin added a comment.

A few things.

1. There is, strangely, a doPhiTranslation function that Value has, you can use that :)

2. Newgvn gets this example case without PRE with my latest patch

It understand the equivalence between op of phis and phi of ops, and so comes up with:

  define void @test1(i64 %a, i64 %b, i64 %c, i64 %d) {
  entry:
    %mul = mul nsw i64 %b, %a
    store i64 %mul, i64* @g1, align 8
    %t0 = load i64, i64* @g2, align 8
    %cmp = icmp sgt i64 %t0, 3
    br i1 %cmp, label %if.then, label %if.end
  
  if.then:                                          ; preds = %entry
    %mul2 = mul nsw i64 %d, %c
    store i64 %mul2, i64* @g2, align 8
    br label %if.end
  
  if.end:                                           ; preds = %if.then, %entry
    %0 = phi i64 [ %mul2, %if.then ], [ %mul, %entry ]
    store i64 %0, i64* @g3, align 8
    ret void
  }



3. I suspect you will have issues with backedges with this approach

I'm pretty sure it will fail in some cases to fixpoint (but maybe gvn is not strong enough to make that happen)

At the very least, you don't want this to transform:

a = phi(0, a + 1)
use a
to
a = phi(0, a + 1)
b = phi(1, a + 2)

etc
It will peel loops ivs if you let it.
In gcc, we specifically check for this case.


Repository:
  rL LLVM

https://reviews.llvm.org/D32252





More information about the llvm-commits mailing list