1 ; RUN: opt -instcombine -S < %s | FileCheck %s
3 ;; This tests that the instructions in the entry blocks are sunk into each
6 define i32 @test1(i1 %C, i32 %A, i32 %B) {
9 %tmp.2 = sdiv i32 %A, %B ; <i32> [#uses=1]
10 %tmp.9 = add i32 %B, %A ; <i32> [#uses=1]
11 br i1 %C, label %then, label %endif
13 then: ; preds = %entry
16 endif: ; preds = %entry
23 ;; PHI use, sink divide before call.
24 define i32 @test2(i32 %x) nounwind ssp {
25 ; CHECK-LABEL: @test2(
30 bb: ; preds = %bb2, %entry
31 %x_addr.17 = phi i32 [ %x, %entry ], [ %x_addr.0, %bb2 ] ; <i32> [#uses=4]
32 %i.06 = phi i32 [ 0, %entry ], [ %4, %bb2 ] ; <i32> [#uses=1]
33 %0 = add nsw i32 %x_addr.17, 1 ; <i32> [#uses=1]
34 %1 = sdiv i32 %0, %x_addr.17 ; <i32> [#uses=1]
35 %2 = icmp eq i32 %x_addr.17, 0 ; <i1> [#uses=1]
36 br i1 %2, label %bb1, label %bb2
40 ; CHECK-NEXT: add nsw i32 %x_addr.17, 1
41 ; CHECK-NEXT: sdiv i32
42 ; CHECK-NEXT: tail call i32 @bar()
43 %3 = tail call i32 @bar() nounwind ; <i32> [#uses=0]
46 bb2: ; preds = %bb, %bb1
47 %x_addr.0 = phi i32 [ %1, %bb1 ], [ %x_addr.17, %bb ] ; <i32> [#uses=2]
48 %4 = add nsw i32 %i.06, 1 ; <i32> [#uses=2]
49 %exitcond = icmp eq i32 %4, 1000000 ; <i1> [#uses=1]
50 br i1 %exitcond, label %bb4, label %bb
58 define i32 @test3(i32* nocapture readonly %P, i32 %i) {
60 %idxprom = sext i32 %i to i64
61 %arrayidx = getelementptr inbounds i32, i32* %P, i64 %idxprom
62 %0 = load i32, i32* %arrayidx, align 4
63 switch i32 %i, label %sw.epilog [
68 sw.bb: ; preds = %entry, %entry
70 ; CHECK: %idxprom = sext i32 %i to i64
71 ; CHECK: %arrayidx = getelementptr inbounds i32, i32* %P, i64 %idxprom
72 ; CHECK: %0 = load i32, i32* %arrayidx, align 4
73 %add = add nsw i32 %0, %i
76 sw.epilog: ; preds = %entry, %sw.bb
77 %sum.0 = phi i32 [ %add, %sw.bb ], [ 0, %entry ]