1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
4 ; Check that debug locations are preserved. For more info see:
5 ; https://llvm.org/docs/SourceLevelDebugging.html#fixing-errors
6 ; RUN: opt < %s -enable-debugify -passes=correlated-propagation -S 2>&1 | \
7 ; RUN: FileCheck %s -check-prefix=DEBUG
8 ; DEBUG: CheckModuleDebugify: PASS
10 declare void @use64(i64)
12 define void @test1(i32 %n) {
13 ; CHECK-LABEL: @test1(
15 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
17 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ [[N:%.*]], [[ENTRY:%.*]] ], [ [[EXT:%.*]], [[FOR_BODY:%.*]] ]
18 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -1
19 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
21 ; CHECK-NEXT: [[EXT_WIDE1:%.*]] = zext nneg i32 [[A]] to i64
22 ; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE1]])
23 ; CHECK-NEXT: [[EXT]] = trunc i64 [[EXT_WIDE1]] to i32
24 ; CHECK-NEXT: br label [[FOR_COND]]
26 ; CHECK-NEXT: ret void
31 for.cond: ; preds = %for.body, %entry
32 %a = phi i32 [ %n, %entry ], [ %ext, %for.body ]
33 %cmp = icmp sgt i32 %a, -1
34 br i1 %cmp, label %for.body, label %for.end
36 for.body: ; preds = %for.cond
37 %ext.wide = sext i32 %a to i64
38 call void @use64(i64 %ext.wide)
39 %ext = trunc i64 %ext.wide to i32
42 for.end: ; preds = %for.cond
46 ;; Negative test to show transform doesn't happen unless n >= 0.
47 define void @test2(i32 %n) {
48 ; CHECK-LABEL: @test2(
50 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
52 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ [[N:%.*]], [[ENTRY:%.*]] ], [ [[EXT:%.*]], [[FOR_BODY:%.*]] ]
53 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A]], -2
54 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
56 ; CHECK-NEXT: [[EXT_WIDE:%.*]] = sext i32 [[A]] to i64
57 ; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE]])
58 ; CHECK-NEXT: [[EXT]] = trunc i64 [[EXT_WIDE]] to i32
59 ; CHECK-NEXT: br label [[FOR_COND]]
61 ; CHECK-NEXT: ret void
66 for.cond: ; preds = %for.body, %entry
67 %a = phi i32 [ %n, %entry ], [ %ext, %for.body ]
68 %cmp = icmp sgt i32 %a, -2
69 br i1 %cmp, label %for.body, label %for.end
71 for.body: ; preds = %for.cond
72 %ext.wide = sext i32 %a to i64
73 call void @use64(i64 %ext.wide)
74 %ext = trunc i64 %ext.wide to i32
77 for.end: ; preds = %for.cond
81 ;; Non looping test case.
82 define void @test3(i32 %n) {
83 ; CHECK-LABEL: @test3(
85 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[N:%.*]], -1
86 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
88 ; CHECK-NEXT: [[EXT_WIDE1:%.*]] = zext nneg i32 [[N]] to i64
89 ; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE1]])
90 ; CHECK-NEXT: [[EXT:%.*]] = trunc i64 [[EXT_WIDE1]] to i32
91 ; CHECK-NEXT: br label [[EXIT]]
93 ; CHECK-NEXT: ret void
96 %cmp = icmp sgt i32 %n, -1
97 br i1 %cmp, label %bb, label %exit
100 %ext.wide = sext i32 %n to i64
101 call void @use64(i64 %ext.wide)
102 %ext = trunc i64 %ext.wide to i32
109 ;; Non looping negative test case.
110 define void @test4(i32 %n) {
111 ; CHECK-LABEL: @test4(
113 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[N:%.*]], -2
114 ; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
116 ; CHECK-NEXT: [[EXT_WIDE:%.*]] = sext i32 [[N]] to i64
117 ; CHECK-NEXT: call void @use64(i64 [[EXT_WIDE]])
118 ; CHECK-NEXT: [[EXT:%.*]] = trunc i64 [[EXT_WIDE]] to i32
119 ; CHECK-NEXT: br label [[EXIT]]
121 ; CHECK-NEXT: ret void
124 %cmp = icmp sgt i32 %n, -2
125 br i1 %cmp, label %bb, label %exit
128 %ext.wide = sext i32 %n to i64
129 call void @use64(i64 %ext.wide)
130 %ext = trunc i64 %ext.wide to i32
137 define i64 @may_including_undef(i1 %c.1, i1 %c.2) {
138 ; CHECK-LABEL: @may_including_undef(
139 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[TRUE_1:%.*]], label [[FALSE:%.*]]
141 ; CHECK-NEXT: br i1 [[C_2:%.*]], label [[TRUE_2:%.*]], label [[EXIT:%.*]]
143 ; CHECK-NEXT: br label [[EXIT]]
145 ; CHECK-NEXT: br label [[EXIT]]
147 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[TRUE_1]] ], [ 1, [[TRUE_2]] ], [ undef, [[FALSE]] ]
148 ; CHECK-NEXT: [[EXT:%.*]] = sext i32 [[P]] to i64
149 ; CHECK-NEXT: ret i64 [[EXT]]
151 br i1 %c.1, label %true.1, label %false
154 br i1 %c.2, label %true.2, label %exit
163 %p = phi i32 [ 0, %true.1 ], [ 1, %true.2], [ undef, %false ]
164 %ext = sext i32 %p to i64