James Molloy | 4f6fb95 | 2012-12-20 16:04:27 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -loop-unswitch -verify-loop-info -S < %s 2>&1 | FileCheck %s |
Chris Lattner | ceea375 | 2004-04-19 18:06:34 +0000 | [diff] [blame] | 2 | |
Tanya Lattner | ab7872c | 2008-03-19 07:28:33 +0000 | [diff] [blame] | 3 | define i32 @test(i32* %A, i1 %C) { |
Chris Lattner | ceea375 | 2004-04-19 18:06:34 +0000 | [diff] [blame] | 4 | entry: |
| 5 | br label %no_exit |
Tanya Lattner | ab7872c | 2008-03-19 07:28:33 +0000 | [diff] [blame] | 6 | no_exit: ; preds = %no_exit.backedge, %entry |
| 7 | %i.0.0 = phi i32 [ 0, %entry ], [ %i.0.0.be, %no_exit.backedge ] ; <i32> [#uses=3] |
| 8 | %gep.upgrd.1 = zext i32 %i.0.0 to i64 ; <i64> [#uses=1] |
| 9 | %tmp.7 = getelementptr i32* %A, i64 %gep.upgrd.1 ; <i32*> [#uses=4] |
| 10 | %tmp.13 = load i32* %tmp.7 ; <i32> [#uses=2] |
| 11 | %tmp.14 = add i32 %tmp.13, 1 ; <i32> [#uses=1] |
| 12 | store i32 %tmp.14, i32* %tmp.7 |
| 13 | br i1 %C, label %then, label %endif |
Chris Lattner | ceea375 | 2004-04-19 18:06:34 +0000 | [diff] [blame] | 14 | then: ; preds = %no_exit |
Tanya Lattner | ab7872c | 2008-03-19 07:28:33 +0000 | [diff] [blame] | 15 | %tmp.29 = load i32* %tmp.7 ; <i32> [#uses=1] |
| 16 | %tmp.30 = add i32 %tmp.29, 2 ; <i32> [#uses=1] |
| 17 | store i32 %tmp.30, i32* %tmp.7 |
| 18 | %inc9 = add i32 %i.0.0, 1 ; <i32> [#uses=2] |
| 19 | %tmp.112 = icmp ult i32 %inc9, 100000 ; <i1> [#uses=1] |
| 20 | br i1 %tmp.112, label %no_exit.backedge, label %return |
| 21 | no_exit.backedge: ; preds = %endif, %then |
| 22 | %i.0.0.be = phi i32 [ %inc9, %then ], [ %inc, %endif ] ; <i32> [#uses=1] |
Chris Lattner | ceea375 | 2004-04-19 18:06:34 +0000 | [diff] [blame] | 23 | br label %no_exit |
Chris Lattner | ceea375 | 2004-04-19 18:06:34 +0000 | [diff] [blame] | 24 | endif: ; preds = %no_exit |
Tanya Lattner | ab7872c | 2008-03-19 07:28:33 +0000 | [diff] [blame] | 25 | %inc = add i32 %i.0.0, 1 ; <i32> [#uses=2] |
| 26 | %tmp.1 = icmp ult i32 %inc, 100000 ; <i1> [#uses=1] |
| 27 | br i1 %tmp.1, label %no_exit.backedge, label %return |
| 28 | return: ; preds = %endif, %then |
| 29 | ret i32 %tmp.13 |
Chris Lattner | ceea375 | 2004-04-19 18:06:34 +0000 | [diff] [blame] | 30 | } |
Tanya Lattner | ab7872c | 2008-03-19 07:28:33 +0000 | [diff] [blame] | 31 | |
James Molloy | 4f6fb95 | 2012-12-20 16:04:27 +0000 | [diff] [blame] | 32 | ; This simple test would normally unswitch, but should be inhibited by the presence of |
| 33 | ; the noduplicate call. |
| 34 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 35 | ; CHECK-LABEL: @test2( |
James Molloy | 4f6fb95 | 2012-12-20 16:04:27 +0000 | [diff] [blame] | 36 | define i32 @test2(i32* %var) { |
| 37 | %mem = alloca i32 |
| 38 | store i32 2, i32* %mem |
| 39 | %c = load i32* %mem |
| 40 | |
| 41 | br label %loop_begin |
| 42 | |
| 43 | loop_begin: |
| 44 | |
| 45 | %var_val = load i32* %var |
| 46 | |
| 47 | switch i32 %c, label %default [ |
| 48 | i32 1, label %inc |
| 49 | i32 2, label %dec |
| 50 | ] |
| 51 | |
| 52 | inc: |
| 53 | call void @incf() noreturn nounwind |
| 54 | br label %loop_begin |
| 55 | dec: |
| 56 | ; CHECK: call void @decf() |
| 57 | ; CHECK-NOT: call void @decf() |
| 58 | call void @decf() noreturn nounwind noduplicate |
| 59 | br label %loop_begin |
| 60 | default: |
| 61 | br label %loop_exit |
| 62 | loop_exit: |
| 63 | ret i32 0 |
| 64 | ; CHECK: } |
| 65 | } |
| 66 | |
| 67 | declare void @incf() noreturn |
| 68 | declare void @decf() noreturn |