[llvm] r304050 - [GVN] Recommit the patch "Add phi-translate support in scalarpre".

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 01:25:11 PDT 2017


On Fri, May 26, 2017 at 5:54 PM, Wei Mi via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: wmi
> Date: Fri May 26 19:54:19 2017
> New Revision: 304050
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304050&view=rev
> Log:
> [GVN] Recommit the patch "Add phi-translate support in scalarpre".
>
> The recommit is to fix a bug about ExtractValue and InsertValue ops. For
> those
> ops, some varargs inside GVN::Expression are not value numbers but raw
> index
> numbers. It is wrong to do phi-translate for raw index numbers, and the
> fix is
> to stop doing that.
>
> Right now scalarpre doesn't have phi-translate support, so it will miss
> some
> simple pre opportunities. Like the following testcase, current scalarpre
> cannot
> recognize the last "a * b" is fully redundent because a and b used by the
> last
> "a * b" expr are both defined by phis.
>
> long a[100], b[100], g1, g2, g3;
> __attribute__((pure)) long goo();
>
> void foo(long a, long b, long c, long d) {
>   g1 = a * b;
>   if (__builtin_expect(g2 > 3, 0)) {
>     a = c;
>     b = d;
>     g2 = a * b;
>   }
>   g3 = a * b;      // fully redundant.
> }
> The patch adds phi-translate support in scalarpre. This is only a temporary
> solution before the newpre based on newgvn is available.
>

Just to mention:
NewGVN does not require PRE to get the case above.
It already gets it :)

In general, any full redundancy that exists in the program will be caught
by newgvn, as it is complete.
(those where it doesn't are deliberate decisions we could change :P)

before -newgvn:
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

@g1 = common global i64 0, align 8
@g2 = common global i64 0, align 8
@g3 = common global i64 0, align 8
@a = common global [100 x i64] zeroinitializer, align 16
@b = common global [100 x i64] zeroinitializer, align 16

; Function Attrs: nounwind ssp uwtable
define void @foo(i64, i64, i64, i64) #0 {
  %5 = mul nsw i64 %0, %1
  store i64 %5, i64* @g1, align 8, !tbaa !2
  %6 = load i64, i64* @g2, align 8, !tbaa !2
  %7 = icmp sgt i64 %6, 3
  %8 = zext i1 %7 to i32
  %9 = sext i32 %8 to i64
  %10 = call i64 @llvm.expect.i64(i64 %9, i64 0)
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %14

; <label>:12:                                     ; preds = %4
  %13 = mul nsw i64 %2, %3
  store i64 %13, i64* @g2, align 8, !tbaa !2
  br label %14

; <label>:14:                                     ; preds = %12, %4
  %.08 = phi i64 [ %3, %12 ], [ %1, %4 ]
  %.0 = phi i64 [ %2, %12 ], [ %0, %4 ]
  %15 = mul nsw i64 %.0, %.08
  store i64 %15, i64* @g3, align 8, !tbaa !2
  ret void
}

after -newgvn:
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

@g1 = common global i64 0, align 8
@g2 = common global i64 0, align 8
@g3 = common global i64 0, align 8
@a = common global [100 x i64] zeroinitializer, align 16
@b = common global [100 x i64] zeroinitializer, align 16

; Function Attrs: nounwind ssp uwtable
define void @foo(i64, i64, i64, i64) #0 {
  %5 = mul nsw i64 %0, %1
  store i64 %5, i64* @g1, align 8, !tbaa !2
  %6 = load i64, i64* @g2, align 8, !tbaa !2
  %7 = icmp sgt i64 %6, 3
  %8 = zext i1 %7 to i32
  %9 = sext i32 %8 to i64
  %10 = call i64 @llvm.expect.i64(i64 %9, i64 0)
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %14

; <label>:12:                                     ; preds = %4
  %13 = mul nsw i64 %2, %3
  store i64 %13, i64* @g2, align 8, !tbaa !2
  br label %14

; <label>:14:                                     ; preds = %12, %4
  %15 = phi i64 [ %13, %12 ], [ %5, %4 ]
  %.08 = phi i64 [ %3, %12 ], [ %1, %4 ]
  %.0 = phi i64 [ %2, %12 ], [ %0, %4 ]
  store i64 %15, i64* @g3, align 8, !tbaa !2
  ret void
}

(note that %15 has been transformed into a phi of the existing values)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170607/bc76713e/attachment.html>


More information about the llvm-commits mailing list