1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -basic-aa -newgvn -S < %s | FileCheck %s
4 ; Function Attrs: noinline norecurse nounwind readonly ssp uwtable
5 define i32 @mp_unsgn_cmp(i32 %n, i32* nocapture readonly %in1, i32* nocapture readonly %in2) local_unnamed_addr {
6 ; CHECK-LABEL: @mp_unsgn_cmp(
8 ; CHECK-NEXT: [[CMP11:%.*]] = icmp sgt i32 [[N:%.*]], -1
9 ; CHECK-NEXT: br i1 [[CMP11]], label [[FOR_INC_PREHEADER:%.*]], label [[IF_ELSE:%.*]]
10 ; CHECK: for.inc.preheader:
11 ; CHECK-NEXT: br label [[FOR_INC:%.*]]
13 ; CHECK-NEXT: [[STOREMERGE2:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC]] ], [ 0, [[FOR_INC_PREHEADER]] ]
14 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[STOREMERGE2]] to i64
15 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[IN1:%.*]], i64 [[IDXPROM]]
16 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
17 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds i32, i32* [[IN2:%.*]], i64 [[IDXPROM]]
18 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[ARRAYIDX4]], align 4
19 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[TMP0]], [[TMP1]]
20 ; CHECK-NEXT: [[INC]] = add nsw i32 [[STOREMERGE2]], 1
21 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[STOREMERGE2]], [[N]]
22 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[SUB]], 0
23 ; CHECK-NEXT: [[OR_COND:%.*]] = and i1 [[CMP2]], [[CMP1]]
24 ; CHECK-NEXT: br i1 [[OR_COND]], label [[FOR_INC]], label [[FOR_END:%.*]]
26 ; CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[SUB]], 0
27 ; CHECK-NEXT: br i1 [[CMP5]], label [[IF_END8:%.*]], label [[IF_ELSE]]
29 ; CHECK-NEXT: [[SUB1_LCSSA4:%.*]] = phi i32 [ [[SUB]], [[FOR_END]] ], [ 0, [[ENTRY:%.*]] ]
30 ; CHECK-NEXT: [[CMP6:%.*]] = icmp slt i32 [[SUB1_LCSSA4]], 0
31 ; CHECK-NEXT: [[DOTSUB1_LCSSA:%.*]] = select i1 [[CMP6]], i32 -1, i32 [[SUB1_LCSSA4]]
32 ; CHECK-NEXT: ret i32 [[DOTSUB1_LCSSA]]
34 ; CHECK-NEXT: ret i32 1
37 %cmp11 = icmp sgt i32 %n, -1
38 br i1 %cmp11, label %for.inc.preheader, label %if.else
40 for.inc.preheader: ; preds = %entry
43 for.inc: ; preds = %for.inc.preheader, %for.inc
44 %storemerge2 = phi i32 [ %inc, %for.inc ], [ 0, %for.inc.preheader ]
45 %idxprom = sext i32 %storemerge2 to i64
46 %arrayidx = getelementptr inbounds i32, i32* %in1, i64 %idxprom
47 %0 = load i32, i32* %arrayidx, align 4
48 %arrayidx4 = getelementptr inbounds i32, i32* %in2, i64 %idxprom
49 %1 = load i32, i32* %arrayidx4, align 4
50 %sub = sub nsw i32 %0, %1
51 %inc = add nsw i32 %storemerge2, 1
52 %cmp1 = icmp slt i32 %storemerge2, %n
53 %cmp2 = icmp eq i32 %sub, 0
54 %or.cond = and i1 %cmp2, %cmp1
55 ;; This is a self-critical edge to for.inc. If we insert predicate info on it, we will insert
56 ;; predicateinfo at the end of this block, and think it dominates everthing using only dfs
57 ;; numbers, instead of proper edge dominance. We would then proceed to propagate the true value
58 ;; of sub == 0 everywhere, making this function only ever return 0.
59 br i1 %or.cond, label %for.inc, label %for.end
61 for.end: ; preds = %for.inc
62 %sub.lcssa = phi i32 [ %sub, %for.inc ]
63 %cmp5 = icmp sgt i32 %sub.lcssa, 0
64 br i1 %cmp5, label %if.end8, label %if.else
66 if.else: ; preds = %entry, %for.end
67 %sub1.lcssa4 = phi i32 [ %sub.lcssa, %for.end ], [ 0, %entry ]
68 %cmp6 = icmp slt i32 %sub1.lcssa4, 0
69 %.sub1.lcssa = select i1 %cmp6, i32 -1, i32 %sub1.lcssa4
72 if.end8: ; preds = %for.end
77 ;; This test will generate a copy of a copy of predicateinfo to the multiple uses
78 ;; of branch conditions below. Make sure we don't try to extract operand info.
79 ; Function Attrs: uwtable
80 define fastcc void @barney() {
81 ; CHECK-LABEL: @barney(
83 ; CHECK-NEXT: br label [[BB22:%.*]]
85 ; CHECK-NEXT: br i1 undef, label [[BB29:%.*]], label [[BB35:%.*]]
87 ; CHECK-NEXT: br i1 true, label [[BB33:%.*]], label [[BB35]]
89 ; CHECK-NEXT: br i1 true, label [[BB35]], label [[BB35]]
91 ; CHECK-NEXT: unreachable
96 %tmp23 = icmp eq i32 undef, 2
97 br i1 %tmp23, label %bb29, label %bb35
100 bb29: ; preds = %bb28
101 br i1 %tmp23, label %bb33, label %bb35
104 bb33: ; preds = %bb31
105 br i1 %tmp23, label %bb35, label %bb35
108 bb35: ; preds = %bb33, %bb29, %bb22