llvm-project/llvm/test/Transforms/GVN/rle-phi-translate.ll

33 lines
1.1 KiB
LLVM
Raw Normal View History

; RUN: opt < %s -gvn -S | grep {%cv = phi i32}
; RUN: opt < %s -gvn -S | grep {%bv = phi i32}
Implement initial support for PHI translation in memdep. This means that memdep keeps track of how PHIs affect the pointer in dep queries, which allows it to eliminate the load in cases like rle-phi-translate.ll, which basically end up being: BB1: X = load P br BB3 BB2: Y = load Q br BB3 BB3: R = phi [P] [Q] load R turning "load R" into a phi of X/Y. In addition to additional exposed opportunities, this makes memdep safe in many cases that it wasn't before (which is required for load PRE) and also makes it substantially more efficient. For example, consider: bb1: // has many predecessors. P = some_operator() load P In this example, previously memdep would scan all the predecessors of BB1 to see if they had something that would mustalias P. In some cases (e.g. test/Transforms/GVN/rle-must-alias.ll) it would actually find them and end up eliminating something. In many other cases though, it would scan and not find anything useful. MemDep now stops at a block if the pointer is defined in that block and cannot be phi translated to predecessors. This causes it to miss the (rare) cases like rle-must-alias.ll, but makes it faster by not scanning tons of stuff that is unlikely to be useful. For example, this speeds up GVN as a whole from 3.928s to 2.448s (60%)!. IMO, scalar GVN should be enhanced to simplify the rle-must-alias pointer base anyway, which would allow the loads to be eliminated. In the future, this should be enhanced to phi translate through geps and bitcasts as well (as indicated by FIXMEs) making memdep even more powerful. llvm-svn: 61022
2008-12-15 11:35:32 +08:00
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "i386-apple-darwin7"
define i32 @g(i32* %b, i32* %c) nounwind {
entry:
%g = alloca i32 ; <i32*> [#uses=4]
%t1 = icmp eq i32* %b, null ; <i1> [#uses=1]
br i1 %t1, label %bb, label %bb1
bb: ; preds = %entry
%t2 = load i32* %c, align 4 ; <i32> [#uses=1]
%t3 = add i32 %t2, 1 ; <i32> [#uses=1]
store i32 %t3, i32* %g, align 4
br label %bb2
bb1: ; preds = %entry
%t5 = load i32* %b, align 4 ; <i32> [#uses=1]
%t6 = add i32 %t5, 1 ; <i32> [#uses=1]
store i32 %t6, i32* %g, align 4
br label %bb2
bb2: ; preds = %bb1, %bb
%c_addr.0 = phi i32* [ %g, %bb1 ], [ %c, %bb ] ; <i32*> [#uses=1]
%b_addr.0 = phi i32* [ %b, %bb1 ], [ %g, %bb ] ; <i32*> [#uses=1]
%cv = load i32* %c_addr.0, align 4 ; <i32> [#uses=1]
%bv = load i32* %b_addr.0, align 4 ; <i32> [#uses=1]
%ret = add i32 %cv, %bv ; <i32> [#uses=1]
ret i32 %ret
}