1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=newgvn -S | FileCheck %s
5 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-grtev4-linux-gnu"
8 define hidden void @barrier() align 2 {
9 ; CHECK-LABEL: @barrier(
11 ; CHECK-NEXT: [[CALLG:%.*]] = tail call i64 @g()
12 ; CHECK-NEXT: [[SEL:%.*]] = select i1 undef, i64 0, i64 [[CALLG]]
13 ; CHECK-NEXT: [[LOADED:%.*]] = load i64, ptr null, align 8
14 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[LOADED]], 1
15 ; CHECK-NEXT: [[SHR17:%.*]] = lshr i64 [[ADD]], 1
16 ; CHECK-NEXT: [[SUB:%.*]] = add nsw i64 [[SHR17]], -1
17 ; CHECK-NEXT: br label [[FIRST:%.*]]
19 ; CHECK-NEXT: [[PHI_ONE:%.*]] = phi i64 [ [[SEL]], [[ENTRY:%.*]] ], [ 0, [[FIRST]] ], [ 0, [[THIRD:%.*]] ]
20 ; CHECK-NEXT: [[CMP_PHI1_SUB:%.*]] = icmp eq i64 [[PHI_ONE]], [[SUB]]
21 ; CHECK-NEXT: br i1 [[CMP_PHI1_SUB]], label [[SECOND:%.*]], label [[FIRST]]
23 ; CHECK-NEXT: br label [[THIRD]]
25 ; CHECK-NEXT: br i1 false, label [[SECOND]], label [[FIRST]]
28 %callg = tail call i64 @g()
29 %sel = select i1 undef, i64 0, i64 %callg
31 %loaded = load i64, ptr null, align 8
32 %add = add i64 %loaded, 1
33 %shr17 = lshr i64 %add, 1
34 %sub = add nsw i64 %shr17, -1
39 %phi_one = phi i64 [ %sel, %entry ], [ 0, %first ], [ 0, %third ]
40 %cmp_phi1_sub = icmp eq i64 %phi_one, %sub
41 br i1 %cmp_phi1_sub, label %second, label %first
44 %phi_two = phi i64 [ %inc, %third ], [ %phi_one, %first ]
48 %inc = add i64 %phi_two, 1
49 %cmp_inc_sub = icmp eq i64 %inc, %sub
50 br i1 %cmp_inc_sub, label %second, label %first
53 define hidden void @barrier2() align 2 {
54 ; CHECK-LABEL: @barrier2(
56 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr null, align 8
57 ; CHECK-NEXT: [[CALL9:%.*]] = tail call i64 @g()
58 ; CHECK-NEXT: [[REM:%.*]] = select i1 undef, i64 0, i64 [[CALL9]]
59 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[TMP0]], 1
60 ; CHECK-NEXT: [[SHR17:%.*]] = lshr i64 [[ADD]], 1
61 ; CHECK-NEXT: [[SUB:%.*]] = add nsw i64 [[SHR17]], -1
62 ; CHECK-NEXT: br label [[MAINLOOP:%.*]]
64 ; CHECK-NEXT: br label [[FIRST_EXIT:%.*]]
66 ; CHECK-NEXT: br label [[MAINLOOP]]
68 ; CHECK-NEXT: [[FIRSTPHI:%.*]] = phi i64 [ [[REM]], [[ENTRY:%.*]] ], [ 0, [[FIRST_EXIT]] ]
69 ; CHECK-NEXT: [[FIRSTCMP:%.*]] = icmp eq i64 [[FIRSTPHI]], [[SUB]]
70 ; CHECK-NEXT: br i1 [[FIRSTCMP]], label [[SECOND_PREHEADER:%.*]], label [[FIRST_EXIT]]
71 ; CHECK: second.preheader:
72 ; CHECK-NEXT: br label [[INNERLOOP:%.*]]
74 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
76 ; CHECK-NEXT: br i1 false, label [[INNERLOOP]], label [[SECOND_EXIT:%.*]]
79 %0 = load i64, ptr null, align 8
80 %call9 = tail call i64 @g()
81 %rem = select i1 undef, i64 0, i64 %call9
83 %shr17 = lshr i64 %add, 1
84 %sub = add nsw i64 %shr17, -1
87 second.exit: ; preds = %cleanup
90 first.exit: ; preds = %mainloop, %second.exit
93 mainloop: ; preds = %first.exit, %entry
94 %firstphi = phi i64 [ %rem, %entry ], [ 0, %first.exit ]
95 %firstcmp = icmp eq i64 %firstphi, %sub
96 br i1 %firstcmp, label %second.preheader, label %first.exit
98 second.preheader: ; preds = %mainloop
101 innerloop: ; preds = %cleanup, %second.preheader
102 %secondphi = phi i64 [ %inc, %cleanup ], [ %firstphi, %second.preheader ]
105 cleanup: ; preds = %innerloop
106 %inc = add i64 %secondphi, 1
107 %secondcmp = icmp eq i64 %inc, %sub
108 br i1 %secondcmp, label %innerloop, label %second.exit
111 declare hidden i64 @g() local_unnamed_addr align 2
113 define void @barrier3(i64 %arg) {
114 ; CHECK-LABEL: @barrier3(
116 ; CHECK-NEXT: br label [[FIRSTLOOP:%.*]]
118 ; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[ARG:%.*]], [[ENTRY:%.*]] ], [ 0, [[FIRSTLOOP]] ]
119 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i64 [[PHI1]], -1
120 ; CHECK-NEXT: br i1 [[CMP1]], label [[SECONDLOOP:%.*]], label [[FIRSTLOOP]]
122 ; CHECK-NEXT: call void @llvm.assume(i1 false)
123 ; CHECK-NEXT: br label [[SECONDLOOP]]
129 %phi1 = phi i64 [ %arg, %entry ], [ 0, %firstloop ]
130 %cmp1 = icmp eq i64 %phi1, -1
131 br i1 %cmp1, label %secondloop, label %firstloop
134 %phi2 = phi i64 [ %inc, %secondloop ], [ %phi1, %firstloop ]
135 %inc = add i64 %phi2, 1
136 %cmp2 = icmp eq i64 %inc, -1
137 call void @llvm.assume(i1 %cmp2)
141 declare void @llvm.assume(i1)