llvm-6502/test/Transforms/GVN/condprop.ll
Duncan Sands 02b5e72ac6 GVN does simple propagation of conditions: when it sees a conditional
branch "br i1 %x, label %if_true, label %if_false" then it replaces
"%x" with "true" in places only reachable via the %if_true arm, and
with "false" in places only reachable via the %if_false arm.  Except
that actually it doesn't: if value numbering shows that %y is equal
to %x then, yes, %y will be turned into true/false in this way, but
any occurrences of %x itself are not transformed.  Fix this.  What's
more, it's often the case that %x is an equality comparison such as
"%x = icmp eq %A, 0", in which case every occurrence of %A that is
only reachable via the %if_true arm can be replaced with 0.  Implement
this and a few other variations on this theme.  This reduces the number
of lines of LLVM IR in "GCC as one big file" by 0.2%.  It has a bigger
impact on Ada code, typically reducing the number of lines of bitcode
by around 0.4% by removing repeated compiler generated checks.  Passes
the LLVM nightly testsuite and the Ada ACATS testsuite.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141177 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-05 14:28:49 +00:00

100 lines
2.0 KiB
LLVM

; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
@a = external global i32 ; <i32*> [#uses=7]
; CHECK: @test1
define i32 @test1() nounwind {
entry:
%0 = load i32* @a, align 4
%1 = icmp eq i32 %0, 4
br i1 %1, label %bb, label %bb1
bb: ; preds = %entry
br label %bb8
bb1: ; preds = %entry
%2 = load i32* @a, align 4
%3 = icmp eq i32 %2, 5
br i1 %3, label %bb2, label %bb3
bb2: ; preds = %bb1
br label %bb8
bb3: ; preds = %bb1
%4 = load i32* @a, align 4
%5 = icmp eq i32 %4, 4
; CHECK: br i1 false, label %bb4, label %bb5
br i1 %5, label %bb4, label %bb5
bb4: ; preds = %bb3
%6 = load i32* @a, align 4
%7 = add i32 %6, 5
br label %bb8
bb5: ; preds = %bb3
%8 = load i32* @a, align 4
%9 = icmp eq i32 %8, 5
; CHECK: br i1 false, label %bb6, label %bb7
br i1 %9, label %bb6, label %bb7
bb6: ; preds = %bb5
%10 = load i32* @a, align 4
%11 = add i32 %10, 4
br label %bb8
bb7: ; preds = %bb5
%12 = load i32* @a, align 4
br label %bb8
bb8: ; preds = %bb7, %bb6, %bb4, %bb2, %bb
%.0 = phi i32 [ %12, %bb7 ], [ %11, %bb6 ], [ %7, %bb4 ], [ 4, %bb2 ], [ 5, %bb ]
br label %return
return: ; preds = %bb8
ret i32 %.0
}
declare void @foo(i1)
; CHECK: @test2
define void @test2(i1 %x, i1 %y) {
%z = or i1 %x, %y
br i1 %z, label %true, label %false
true:
; CHECK: true:
%z2 = or i1 %x, %y
call void @foo(i1 %z2)
; CHECK: call void @foo(i1 true)
br label %true
false:
; CHECK: false:
%z3 = or i1 %x, %y
call void @foo(i1 %z3)
; CHECK: call void @foo(i1 false)
br label %false
}
declare void @bar(i32)
; CHECK: @test3
define void @test3(i32 %x, i32 %y) {
%xz = icmp eq i32 %x, 0
%yz = icmp eq i32 %y, 0
%z = and i1 %xz, %yz
br i1 %z, label %both_zero, label %nope
both_zero:
call void @foo(i1 %xz)
; CHECK: call void @foo(i1 true)
call void @foo(i1 %yz)
; CHECK: call void @foo(i1 true)
call void @bar(i32 %x)
; CHECK: call void @bar(i32 0)
call void @bar(i32 %y)
; CHECK: call void @bar(i32 0)
ret void
nope:
call void @foo(i1 %z)
; CHECK: call void @foo(i1 false)
ret void
}