1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=indvars -replexitval=always -S | FileCheck %s --check-prefix=ALWAYS
3 ; RUN: opt < %s -passes=indvars -replexitval=never -S | FileCheck %s --check-prefix=NEVER
4 ; RUN: opt < %s -passes=indvars -replexitval=cheap -scev-cheap-expansion-budget=1 -S | FileCheck %s --check-prefix=CHEAP
6 ; rewriteLoopExitValues() must rewrite all or none of a PHI's values from a given block.
8 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10 @a = common global i8 0, align 1
12 define internal fastcc void @d(ptr %c) unnamed_addr #0 {
15 ; ALWAYS-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[C:%.*]], i64 -65535
16 ; ALWAYS-NEXT: [[TMP0:%.*]] = icmp ugt ptr [[C]], @a
17 ; ALWAYS-NEXT: [[UMAX:%.*]] = select i1 [[TMP0]], ptr [[C]], ptr @a
18 ; ALWAYS-NEXT: br label [[WHILE_COND:%.*]]
20 ; ALWAYS-NEXT: br i1 false, label [[CONT:%.*]], label [[WHILE_END_LOOPEXIT:%.*]]
22 ; ALWAYS-NEXT: switch i64 0, label [[WHILE_COND]] [
23 ; ALWAYS-NEXT: i64 -1, label [[HANDLER_POINTER_OVERFLOW_I:%.*]]
24 ; ALWAYS-NEXT: i64 0, label [[HANDLER_POINTER_OVERFLOW_I]]
26 ; ALWAYS: handler.pointer_overflow.i:
27 ; ALWAYS-NEXT: [[A_MUX_LCSSA4:%.*]] = phi ptr [ [[UMAX]], [[CONT]] ], [ [[UMAX]], [[CONT]] ]
28 ; ALWAYS-NEXT: [[X5:%.*]] = ptrtoint ptr [[A_MUX_LCSSA4]] to i64
29 ; ALWAYS-NEXT: br label [[WHILE_END:%.*]]
30 ; ALWAYS: while.end.loopexit:
31 ; ALWAYS-NEXT: br label [[WHILE_END]]
33 ; ALWAYS-NEXT: ret void
37 ; NEVER-NEXT: [[CMP:%.*]] = icmp ule ptr [[C:%.*]], @a
38 ; NEVER-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[C]], i64 -65535
39 ; NEVER-NEXT: br label [[WHILE_COND:%.*]]
41 ; NEVER-NEXT: br i1 false, label [[CONT:%.*]], label [[WHILE_END_LOOPEXIT:%.*]]
43 ; NEVER-NEXT: [[A_MUX:%.*]] = select i1 [[CMP]], ptr @a, ptr [[C]]
44 ; NEVER-NEXT: switch i64 0, label [[WHILE_COND]] [
45 ; NEVER-NEXT: i64 -1, label [[HANDLER_POINTER_OVERFLOW_I:%.*]]
46 ; NEVER-NEXT: i64 0, label [[HANDLER_POINTER_OVERFLOW_I]]
48 ; NEVER: handler.pointer_overflow.i:
49 ; NEVER-NEXT: [[A_MUX_LCSSA4:%.*]] = phi ptr [ [[A_MUX]], [[CONT]] ], [ [[A_MUX]], [[CONT]] ]
50 ; NEVER-NEXT: [[X5:%.*]] = ptrtoint ptr [[A_MUX_LCSSA4]] to i64
51 ; NEVER-NEXT: br label [[WHILE_END:%.*]]
52 ; NEVER: while.end.loopexit:
53 ; NEVER-NEXT: br label [[WHILE_END]]
55 ; NEVER-NEXT: ret void
59 ; CHEAP-NEXT: [[CMP:%.*]] = icmp ule ptr [[C:%.*]], @a
60 ; CHEAP-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[C]], i64 -65535
61 ; CHEAP-NEXT: br label [[WHILE_COND:%.*]]
63 ; CHEAP-NEXT: br i1 false, label [[CONT:%.*]], label [[WHILE_END_LOOPEXIT:%.*]]
65 ; CHEAP-NEXT: [[A_MUX:%.*]] = select i1 [[CMP]], ptr @a, ptr [[C]]
66 ; CHEAP-NEXT: switch i64 0, label [[WHILE_COND]] [
67 ; CHEAP-NEXT: i64 -1, label [[HANDLER_POINTER_OVERFLOW_I:%.*]]
68 ; CHEAP-NEXT: i64 0, label [[HANDLER_POINTER_OVERFLOW_I]]
70 ; CHEAP: handler.pointer_overflow.i:
71 ; CHEAP-NEXT: [[A_MUX_LCSSA4:%.*]] = phi ptr [ [[A_MUX]], [[CONT]] ], [ [[A_MUX]], [[CONT]] ]
72 ; CHEAP-NEXT: [[X5:%.*]] = ptrtoint ptr [[A_MUX_LCSSA4]] to i64
73 ; CHEAP-NEXT: br label [[WHILE_END:%.*]]
74 ; CHEAP: while.end.loopexit:
75 ; CHEAP-NEXT: br label [[WHILE_END]]
77 ; CHEAP-NEXT: ret void
80 %cmp = icmp ule ptr %c, @a
81 %add.ptr = getelementptr inbounds i8, ptr %c, i64 -65535
85 br i1 icmp ne (i8 0, i8 0), label %cont, label %while.end
88 %a.mux = select i1 %cmp, ptr @a, ptr %c
89 switch i64 0, label %while.cond [
90 i64 -1, label %handler.pointer_overflow.i
91 i64 0, label %handler.pointer_overflow.i
94 handler.pointer_overflow.i:
95 %a.mux.lcssa4 = phi ptr [ %a.mux, %cont ], [ %a.mux, %cont ]
96 %x5 = ptrtoint ptr %a.mux.lcssa4 to i64