1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=indvars -S %s -o - | FileCheck %s
4 ; When bailing out in rewriteLoopExitValues() you would be left with a PHI node
5 ; that was not deleted, and the IndVar pass would return an incorrect modified
6 ; status. This was caught by the expensive check introduced in D86589.
8 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9 target triple = "x86_64-unknown-linux-gnu"
11 @ptr = external global i64
13 define dso_local void @hoge() local_unnamed_addr {
16 ; CHECK-NEXT: [[N:%.*]] = sdiv exact i64 undef, 40
17 ; CHECK-NEXT: [[TMP0:%.*]] = sub i64 undef, [[N]]
18 ; CHECK-NEXT: br label [[HEADER:%.*]]
20 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LATCH:%.*]] ], [ [[TMP0]], [[ENTRY:%.*]] ]
21 ; CHECK-NEXT: [[IDX:%.*]] = phi i64 [ [[IDX_NEXT:%.*]], [[LATCH]] ], [ undef, [[ENTRY]] ]
22 ; CHECK-NEXT: [[COND:%.*]] = icmp sgt i64 [[N]], [[IDX]]
23 ; CHECK-NEXT: br i1 [[COND]], label [[END:%.*]], label [[INNER_PREHEADER:%.*]]
24 ; CHECK: inner.preheader:
25 ; CHECK-NEXT: br label [[INNER:%.*]]
27 ; CHECK-NEXT: [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], [[INNER]] ], [ 0, [[INNER_PREHEADER]] ]
28 ; CHECK-NEXT: [[I_NEXT]] = add nuw i64 [[I]], 1
29 ; CHECK-NEXT: store i64 undef, ptr @ptr, align 8
30 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[I_NEXT]], [[INDVARS_IV]]
31 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[INNER]], label [[INNER_EXIT:%.*]]
33 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ [[I_NEXT]], [[INNER]] ]
34 ; CHECK-NEXT: [[INDVAR_USE:%.*]] = add i64 [[INDVAR]], 1
35 ; CHECK-NEXT: br label [[LATCH]]
37 ; CHECK-NEXT: [[IDX_NEXT]] = add nsw i64 [[IDX]], -1
38 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], -1
39 ; CHECK-NEXT: br label [[HEADER]]
41 ; CHECK-NEXT: ret void
43 entry: ; preds = %entry
44 %n = sdiv exact i64 undef, 40
47 header: ; preds = %latch, %entry
48 %idx = phi i64 [ %idx.next, %latch ], [ undef, %entry ]
49 %cond = icmp sgt i64 %n, %idx
50 br i1 %cond, label %end, label %inner
52 inner: ; preds = %inner, %header
53 %i = phi i64 [ %i.next, %inner ], [ 0, %header ]
54 %j = phi i64 [ %j.next, %inner ], [ %n, %header ]
55 %i.next = add nsw i64 %i, 1
56 %j.next = add nsw i64 %j, 1
57 store i64 undef, ptr @ptr
58 %cond1 = icmp slt i64 %j, %idx
59 br i1 %cond1, label %inner, label %inner_exit
61 inner_exit: ; preds = %inner
62 %indvar = phi i64 [ %i.next, %inner ]
63 %indvar_use = add i64 %indvar, 1
66 latch: ; preds = %inner_exit
67 %idx.next = add nsw i64 %idx, -1
70 end: ; preds = %header