llvm.org GIT mirror llvm / d021f41
[SCEV] Pass NoWrapFlags when expanding an AddExpr InsertBinop now accepts NoWrapFlags, so pass them through when expanding a simple add expression. This is the first re-commit of the functional changes from rL362687, which was previously reverted. Differential Revision: https://reviews.llvm.org/D61934 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363364 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Parker 3 months ago
15 changed file(s) with 25 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
752752 Sum = InsertNoopCastOfTo(Sum, Ty);
753753 // Canonicalize a constant to the RHS.
754754 if (isa(Sum)) std::swap(Sum, W);
755 Sum = InsertBinop(Instruction::Add, Sum, W, SCEV::FlagAnyWrap,
755 Sum = InsertBinop(Instruction::Add, Sum, W, S->getNoWrapFlags(),
756756 /*IsSafeToHoist*/ true);
757757 ++I;
758758 }
7575 ; CHECK: while.body.lr.ph:
7676 ; CHECK: [[ROUND:%[^ ]+]] = add i32 %n, -1
7777 ; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[ROUND]], 1
78 ; CHECK: [[COUNT:%[^ ]+]] = add i32 [[HALVE]], 1
78 ; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1
7979 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
8080 ; CHECK-NEXT: br label %while.body
8181
118118 ; CHECK: [[SMIN:%[^ ]+]] = select i1 [[CMP]], i32 %n, i32 2
119119 ; CHECK: [[SUB:%[^ ]+]] = sub i32 [[ROUND]], [[SMIN]]
120120 ; CHECK: [[HALVE:%[^ ]+]] = lshr i32 [[SUB]], 1
121 ; CHECK: [[COUNT:%[^ ]+]] = add i32 [[HALVE]], 1
121 ; CHECK: [[COUNT:%[^ ]+]] = add nuw i32 [[HALVE]], 1
122122 ; CHECK: call void @llvm.set.loop.iterations.i32(i32 [[COUNT]])
123123 ; CHECK-NEXT: br label %while.body
124124
8888 ; CHECK: entry:
8989 ; CHECK-NEXT: %num = load i64, i64* %p1, align 4
9090 ; CHECK-NEXT: [[DIV:%[^ ]+]] = udiv i64 %num, 13
91 ; CHECK-NEXT: [[DIV_MINUS_1:%[^ ]+]] = add i64 [[DIV]], -1
91 ; CHECK-NEXT: [[DIV_MINUS_1:%[^ ]+]] = add nsw i64 [[DIV]], -1
9292 ; CHECK-NEXT: [[COMP1:%[^ ]+]] = icmp sgt i64 [[DIV_MINUS_1]], 0
9393 ; CHECK-NEXT: %exit.mainloop.at = select i1 [[COMP1]], i64 [[DIV_MINUS_1]], i64 0
9494 ; CHECK-NEXT: [[COMP2:%[^ ]+]] = icmp slt i64 0, %exit.mainloop.at
44 ; CHECK-LABEL: @f_0(
55
66 ; CHECK: loop.preheader:
7 ; CHECK: [[len_sub:[^ ]+]] = add i32 %len, -4
7 ; CHECK: [[len_sub:[^ ]+]] = add nsw i32 %len, -4
88 ; CHECK: [[exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp slt i32 %n, [[len_sub]]
99 ; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[exit_main_loop_at_hiclamp_cmp]], i32 %n, i32 [[len_sub]]
1010 ; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0
3232 ; CHECK: [[len_hiclamp:[^ ]+]] = select i1 [[len_hiclamp_cmp]], i32 %len, i32 %n
3333 ; CHECK: [[not_exit_preloop_at_cmp:[^ ]+]] = icmp sgt i32 [[len_hiclamp]], 0
3434 ; CHECK: [[not_exit_preloop_at:[^ ]+]] = select i1 [[not_exit_preloop_at_cmp]], i32 [[len_hiclamp]], i32 0
35 ; CHECK: %exit.preloop.at = add i32 [[not_exit_preloop_at]], -1
35 ; CHECK: %exit.preloop.at = add nsw i32 [[not_exit_preloop_at]], -1
3636 }
3737
3838 ; Make sure that we can eliminate the range check when the loop looks like:
2222 ; CHECK-NOT: preloop
2323 ; CHECK: entry:
2424 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
25 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add i32 %len, -13
25 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add nsw i32 %len, -13
2626 ; CHECK-NEXT: [[CMP1:%[^ ]+]] = icmp slt i32 [[SUB1]], 101
2727 ; CHECK-NEXT: [[SMAX:%[^ ]+]] = select i1 [[CMP1]], i32 [[SUB1]], i32 101
2828 ; CHECK-NEXT: [[CMP2:%[^ ]+]] = icmp sgt i32 [[SMAX]], 0
7878 ; CHECK-LABEL: test_02(
7979 ; CHECK: entry:
8080 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
81 ; CHECK-NEXT: [[LEN_MINUS_SMAX:%[^ ]+]] = add i32 %len, -2147483647
81 ; CHECK-NEXT: [[LEN_MINUS_SMAX:%[^ ]+]] = add nuw nsw i32 %len, -2147483647
8282 ; CHECK-NEXT: [[CMP1:%[^ ]+]] = icmp sgt i32 [[LEN_MINUS_SMAX]], -13
8383 ; CHECK-NEXT: [[SMAX1:%[^ ]+]] = select i1 [[CMP1]], i32 [[LEN_MINUS_SMAX]], i32 -13
8484 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = sub i32 %len, [[SMAX1]]
201201 ; CHECK-LABEL: test_04(
202202 ; CHECK: entry:
203203 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
204 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add i32 %len, 13
204 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add nuw i32 %len, 13
205205 ; CHECK-NEXT: [[CMP1:%[^ ]+]] = icmp ult i32 [[SUB1]], 101
206206 ; CHECK-NEXT: %exit.mainloop.at = select i1 [[CMP1]], i32 [[SUB1]], i32 101
207207 ; CHECK-NEXT: br i1 true, label %loop.preloop.preheader
244244 ; CHECK-NOT: preloop
245245 ; CHECK: entry:
246246 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
247 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add i32 %len, -13
247 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add nsw i32 %len, -13
248248 ; CHECK-NEXT: [[CMP1:%[^ ]+]] = icmp slt i32 [[SUB1]], 101
249249 ; CHECK-NEXT: [[SMAX:%[^ ]+]] = select i1 [[CMP1]], i32 [[SUB1]], i32 101
250250 ; CHECK-NEXT: [[CMP2:%[^ ]+]] = icmp sgt i32 [[SMAX]], 0
285285 ; CHECK-LABEL: test_06(
286286 ; CHECK: entry:
287287 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
288 ; CHECK-NEXT: [[LEN_MINUS_SMAX:%[^ ]+]] = add i32 %len, -2147483647
288 ; CHECK-NEXT: [[LEN_MINUS_SMAX:%[^ ]+]] = add nuw nsw i32 %len, -2147483647
289289 ; CHECK-NEXT: [[CMP1:%[^ ]+]] = icmp sgt i32 [[LEN_MINUS_SMAX]], -13
290290 ; CHECK-NEXT: [[SMAX1:%[^ ]+]] = select i1 [[CMP1]], i32 [[LEN_MINUS_SMAX]], i32 -13
291291 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = sub i32 %len, [[SMAX1]]
374374 ; CHECK-LABEL: test_08(
375375 ; CHECK: entry:
376376 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
377 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add i32 %len, 13
377 ; CHECK-NEXT: [[SUB1:%[^ ]+]] = add nuw i32 %len, 13
378378 ; CHECK-NEXT: [[CMP1:%[^ ]+]] = icmp ult i32 [[SUB1]], 101
379379 ; CHECK-NEXT: %exit.mainloop.at = select i1 [[CMP1]], i32 [[SUB1]], i32 101
380380 ; CHECK-NEXT: br i1 true, label %loop.preloop.preheader
8585 ; CHECK-LABEL: @single_access_no_preloop_with_offset(
8686
8787 ; CHECK: loop.preheader:
88 ; CHECK: [[safe_range_end:[^ ]+]] = add i32 %len, -4
88 ; CHECK: [[safe_range_end:[^ ]+]] = add nsw i32 %len, -4
8989 ; CHECK: [[exit_main_loop_at_hiclamp_cmp:[^ ]+]] = icmp slt i32 %n, [[safe_range_end]]
9090 ; CHECK: [[exit_main_loop_at_hiclamp:[^ ]+]] = select i1 [[exit_main_loop_at_hiclamp_cmp]], i32 %n, i32 [[safe_range_end]]
9191 ; CHECK: [[exit_main_loop_at_loclamp_cmp:[^ ]+]] = icmp sgt i32 [[exit_main_loop_at_hiclamp]], 0
4040 ; CHECK: [[exit_preloop_at:[^ ]+]] = select i1 [[exit_preloop_at_cond]], i32 [[exit_preloop_at_loclamp]], i32 0
4141
4242
43 ; CHECK: [[len_minus_sint_max:[^ ]+]] = add i32 %len, -2147483647
43 ; CHECK: [[len_minus_sint_max:[^ ]+]] = add nuw nsw i32 %len, -2147483647
4444 ; CHECK: [[check_len_min_sint_offset:[^ ]+]] = icmp sgt i32 %offset, [[len_minus_sint_max]]
4545 ; CHECK: [[safe_offset_mainloop:[^ ]+]] = select i1 [[check_len_min_sint_offset]], i32 %offset, i32 [[len_minus_sint_max]]
4646 ; If Offset was a SINT_MIN, we could have an overflow here. That is why we calculated its safe version.
253253 ; CHECK: @test_05(
254254 ; CHECK: entry:
255255 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr
256 ; CHECK-NEXT: %exit.preloop.at = add i32 %len, -1
256 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 %len, -1
257257 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp sgt i32 100, %exit.preloop.at
258258 ; CHECK-NEXT: br i1 [[COND1]], label %loop.preloop.preheader, label %preloop.pseudo.exit
259259 ; CHECK: loop.preloop.preheader:
319319 ; CHECK: @test_06(
320320 ; CHECK: entry:
321321 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr
322 ; CHECK-NEXT: %exit.preloop.at = add i32 %len, -1
322 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 %len, -1
323323 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ugt i32 2147483640, %exit.preloop.at
324324 ; CHECK-NEXT: br i1 [[COND1]], label %loop.preloop.preheader, label %preloop.pseudo.exit
325325 ; CHECK: loop.preloop.preheader:
414414 ; CHECK: @test_08(
415415 ; CHECK: entry:
416416 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr
417 ; CHECK-NEXT: %exit.preloop.at = add i32 %len, -1
417 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 %len, -1
418418 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ugt i32 2147483647, %exit.preloop.at
419419 ; CHECK-NEXT: br i1 [[COND1]], label %loop.preloop.preheader, label %preloop.pseudo.exit
420420 ; CHECK: loop.preloop.preheader:
5858 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
5959 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ugt i32 %len, 1
6060 ; CHECK-NEXT: [[UMIN:%[^ ]+]] = select i1 [[COND1]], i32 %len, i32 1
61 ; CHECK-NEXT: %exit.preloop.at = add i32 [[UMIN]], -1
61 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 [[UMIN]], -1
6262 ; CHECK-NEXT: [[COND2:%[^ ]+]] = icmp ugt i32 100, %exit.preloop.at
6363 ; CHECK-NEXT: br i1 [[COND2]], label %loop.preloop.preheader, label %preloop.pseudo.exit
6464 ; CHECK: mainloop:
149149 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
150150 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ugt i32 %len, 1
151151 ; CHECK-NEXT: [[UMIN:%[^ ]+]] = select i1 [[COND1]], i32 %len, i32 1
152 ; CHECK-NEXT: %exit.preloop.at = add i32 [[UMIN]], -1
152 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 [[UMIN]], -1
153153 ; CHECK-NEXT: [[COND2:%[^ ]+]] = icmp ugt i32 -2147483648, %exit.preloop.at
154154 ; CHECK-NEXT: br i1 [[COND2]], label %loop.preloop.preheader, label %preloop.pseudo.exit
155155 ; CHECK: mainloop:
6161 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
6262 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ugt i32 %len, 1
6363 ; CHECK-NEXT: [[UMIN:%[^ ]+]] = select i1 [[COND1]], i32 %len, i32 1
64 ; CHECK-NEXT: %exit.preloop.at = add i32 [[UMIN]], -1
64 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 [[UMIN]], -1
6565 ; CHECK-NEXT: [[COND2:%[^ ]+]] = icmp ugt i32 100, %exit.preloop.at
6666 ; CHECK-NEXT: br i1 [[COND2]], label %loop.preloop.preheader, label %preloop.pseudo.exit
6767 ; CHECK: mainloop:
194194 ; CHECK-NEXT: %len = load i32, i32* %a_len_ptr, !range !0
195195 ; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ugt i32 %len, 1
196196 ; CHECK-NEXT: [[UMIN:%[^ ]+]] = select i1 [[COND1]], i32 %len, i32 1
197 ; CHECK-NEXT: %exit.preloop.at = add i32 [[UMIN]], -1
197 ; CHECK-NEXT: %exit.preloop.at = add nsw i32 [[UMIN]], -1
198198 ; CHECK-NEXT: [[COND2:%[^ ]+]] = icmp ugt i32 -2147483648, %exit.preloop.at
199199 ; CHECK-NEXT: br i1 [[COND2]], label %loop.preloop.preheader, label %preloop.pseudo.exit
200200 ; CHECK: mainloop:
201201 ; CHECK: loop.preheader:
202202 ; CHECK-NEXT: [[TMP0:%.*]] = add i8 [[N]], 3
203203 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[TMP0]], 2
204 ; CHECK-NEXT: [[TMP2:%.*]] = add i8 [[TMP1]], 1
204 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i8 [[TMP1]], 1
205205 ; CHECK-NEXT: br label [[LOOP:%.*]]
206206 ; CHECK: loop:
207207 ; CHECK-NEXT: [[I1:%.*]] = phi i8 [ [[I1_INC:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
2424 ; CHECK-LABEL: @test2
2525 ; CHECK: [[VAR1:%.+]] = add i32 %arg, -11
2626 ; CHECK: [[VAR2:%.+]] = lshr i32 [[VAR1]], 1
27 ; CHECK: [[VAR3:%.+]] = add i32 [[VAR2]], 1
27 ; CHECK: [[VAR3:%.+]] = add nuw i32 [[VAR2]], 1
2828 ; CHECK: [[VAR4:%.+]] = phi i32 [ 0, %bb ], [ [[VAR3]], %bb1.preheader ]
2929 ; CHECK: ret i32 [[VAR4]]
3030 define i32 @test2(i32 %arg) {
1313 ; CHECK-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[SIZE:%.*]], 1
1414 ; CHECK-NEXT: [[T0:%.*]] = zext i32 [[SIZE]] to i64
1515 ; CHECK-NEXT: [[T1:%.*]] = sext i32 [[NSTEPS:%.*]] to i64
16 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[T0]], -1
16 ; CHECK-NEXT: [[TMP0:%.*]] = add nsw i64 [[T0]], -1
1717 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
1818 ; CHECK: for.body:
1919 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ [[LSR_IV_NEXT2:%.*]], [[FOR_INC:%.*]] ], [ 1, [[ENTRY:%.*]] ]
2626 ; CHECK: for.body3.lr.ph.us.preheader:
2727 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[M]], -1
2828 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
29 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], 1
29 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
3030 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[K:%.*]] to i64
3131 ; CHECK-NEXT: br label [[FOR_BODY3_LR_PH_US:%.*]]
3232 ; CHECK: for.end.us: