1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00
llvm-mirror/test/Transforms/GVNSink/struct.ll
James Molloy e219c46616 [GVNSink] GVNSink pass
This patch provides an initial prototype for a pass that sinks instructions based on GVN information, similar to GVNHoist. It is not yet ready for commiting but I've uploaded it to gather some initial thoughts.

This pass attempts to sink instructions into successors, reducing static
instruction count and enabling if-conversion.
We use a variant of global value numbering to decide what can be sunk.
Consider:

[ %a1 = add i32 %b, 1  ]   [ %c1 = add i32 %d, 1  ]
[ %a2 = xor i32 %a1, 1 ]   [ %c2 = xor i32 %c1, 1 ]
                 \           /
           [ %e = phi i32 %a2, %c2 ]
           [ add i32 %e, 4         ]

GVN would number %a1 and %c1 differently because they compute different
results - the VN of an instruction is a function of its opcode and the
transitive closure of its operands. This is the key property for hoisting
and CSE.

What we want when sinking however is for a numbering that is a function of
the *uses* of an instruction, which allows us to answer the question "if I
replace %a1 with %c1, will it contribute in an equivalent way to all
successive instructions?". The (new) PostValueTable class in GVN provides this
mapping.

This pass has some shown really impressive improvements especially for codesize already on internal benchmarks, so I have high hopes it can replace all the sinking logic in SimplifyCFG.

Differential revision: https://reviews.llvm.org/D24805

llvm-svn: 303850
2017-05-25 12:51:11 +00:00

71 lines
1.9 KiB
LLVM

; RUN: opt -gvn-sink -S < %s | FileCheck %s
%struct = type {i32, i32}
%struct2 = type { [ 2 x i32], i32 }
; Struct indices cannot be variant.
; CHECK-LABEL: @f() {
; CHECK: getelementptr
; CHECK: getelementptr
define void @f() {
bb:
br i1 undef, label %bb2, label %bb1
bb1: ; preds = %bb
%tmp = getelementptr inbounds %struct, %struct* null, i64 0, i32 1
br label %bb4
bb2: ; preds = %bb
%tmp3 = getelementptr inbounds %struct, %struct* null, i64 0, i32 0
br label %bb4
bb4: ; preds = %bb2, %bb1
%tmp5 = phi i32 [ 1, %bb1 ], [ 0, %bb2 ]
ret void
}
; Struct indices cannot be variant.
; CHECK-LABEL: @g() {
; CHECK: getelementptr
; CHECK: getelementptr
define void @g() {
bb:
br i1 undef, label %bb2, label %bb1
bb1: ; preds = %bb
%tmp = getelementptr inbounds %struct2, %struct2* null, i64 0, i32 0, i32 1
br label %bb4
bb2: ; preds = %bb
%tmp3 = getelementptr inbounds %struct2, %struct2* null, i64 0, i32 0, i32 0
br label %bb4
bb4: ; preds = %bb2, %bb1
%tmp5 = phi i32 [ 1, %bb1 ], [ 0, %bb2 ]
ret void
}
; ... but the first parameter to a GEP can.
; CHECK-LABEL: @h() {
; CHECK: getelementptr
; CHECK-NOT: getelementptr
define void @h() {
bb:
br i1 undef, label %bb2, label %bb1
bb1: ; preds = %bb
%tmp = getelementptr inbounds %struct, %struct* null, i32 0, i32 0
br label %bb4
bb2: ; preds = %bb
%tmp3 = getelementptr inbounds %struct, %struct* null, i32 1, i32 0
br label %bb4
bb4: ; preds = %bb2, %bb1
%tmp5 = phi i32 [ 0, %bb1 ], [ 1, %bb2 ]
ret void
}