1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -S -riscv-codegenprepare -mtriple=riscv64 | FileCheck %s
4 ; Make sure we convert the 4294967294 in for.body.preheader.new to -2 based on
5 ; the upper 33 bits being zero by the dominating condition %cmp3.
6 define void @test2(ptr nocapture noundef %a, i32 noundef signext %n) {
9 ; CHECK-NEXT: [[CMP3:%.*]] = icmp sgt i32 [[N:%.*]], 0
10 ; CHECK-NEXT: br i1 [[CMP3]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
11 ; CHECK: for.body.preheader:
12 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext nneg i32 [[N]] to i64
13 ; CHECK-NEXT: [[XTRAITER:%.*]] = and i64 [[WIDE_TRIP_COUNT]], 1
14 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[N]], 1
15 ; CHECK-NEXT: br i1 [[TMP0]], label [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA:%.*]], label [[FOR_BODY_PREHEADER_NEW:%.*]]
16 ; CHECK: for.body.preheader.new:
17 ; CHECK-NEXT: [[UNROLL_ITER:%.*]] = and i64 [[WIDE_TRIP_COUNT]], -2
18 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
19 ; CHECK: for.cond.cleanup.loopexit.unr-lcssa:
20 ; CHECK-NEXT: [[INDVARS_IV_UNR:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[INDVARS_IV_NEXT_1:%.*]], [[FOR_BODY]] ]
21 ; CHECK-NEXT: [[LCMP_MOD_NOT:%.*]] = icmp eq i64 [[XTRAITER]], 0
22 ; CHECK-NEXT: br i1 [[LCMP_MOD_NOT]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY_EPIL:%.*]]
23 ; CHECK: for.body.epil:
24 ; CHECK-NEXT: [[ARRAYIDX_EPIL:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[INDVARS_IV_UNR]]
25 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX_EPIL]], align 4
26 ; CHECK-NEXT: [[ADD_EPIL:%.*]] = add nsw i32 [[TMP1]], 4
27 ; CHECK-NEXT: store i32 [[ADD_EPIL]], ptr [[ARRAYIDX_EPIL]], align 4
28 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
29 ; CHECK: for.cond.cleanup:
30 ; CHECK-NEXT: ret void
32 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER_NEW]] ], [ [[INDVARS_IV_NEXT_1]], [[FOR_BODY]] ]
33 ; CHECK-NEXT: [[NITER:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER_NEW]] ], [ [[NITER_NEXT_1:%.*]], [[FOR_BODY]] ]
34 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
35 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
36 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP2]], 4
37 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX]], align 4
38 ; CHECK-NEXT: [[INDVARS_IV_NEXT:%.*]] = or i64 [[INDVARS_IV]], 1
39 ; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV_NEXT]]
40 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX_1]], align 4
41 ; CHECK-NEXT: [[ADD_1:%.*]] = add nsw i32 [[TMP3]], 4
42 ; CHECK-NEXT: store i32 [[ADD_1]], ptr [[ARRAYIDX_1]], align 4
43 ; CHECK-NEXT: [[INDVARS_IV_NEXT_1]] = add nuw nsw i64 [[INDVARS_IV]], 2
44 ; CHECK-NEXT: [[NITER_NEXT_1]] = add i64 [[NITER]], 2
45 ; CHECK-NEXT: [[NITER_NCMP_1:%.*]] = icmp eq i64 [[NITER_NEXT_1]], [[UNROLL_ITER]]
46 ; CHECK-NEXT: br i1 [[NITER_NCMP_1]], label [[FOR_COND_CLEANUP_LOOPEXIT_UNR_LCSSA]], label [[FOR_BODY]]
49 %cmp3 = icmp sgt i32 %n, 0
50 br i1 %cmp3, label %for.body.preheader, label %for.cond.cleanup
52 for.body.preheader: ; preds = %entry
53 %wide.trip.count = zext nneg i32 %n to i64
54 %xtraiter = and i64 %wide.trip.count, 1
55 %0 = icmp eq i32 %n, 1
56 br i1 %0, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body.preheader.new
58 for.body.preheader.new: ; preds = %for.body.preheader
59 %unroll_iter = and i64 %wide.trip.count, 4294967294
62 for.cond.cleanup.loopexit.unr-lcssa: ; preds = %for.body, %for.body.preheader
63 %indvars.iv.unr = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next.1, %for.body ]
64 %lcmp.mod.not = icmp eq i64 %xtraiter, 0
65 br i1 %lcmp.mod.not, label %for.cond.cleanup, label %for.body.epil
67 for.body.epil: ; preds = %for.cond.cleanup.loopexit.unr-lcssa
68 %arrayidx.epil = getelementptr inbounds i32, ptr %a, i64 %indvars.iv.unr
69 %1 = load i32, ptr %arrayidx.epil, align 4
70 %add.epil = add nsw i32 %1, 4
71 store i32 %add.epil, ptr %arrayidx.epil, align 4
72 br label %for.cond.cleanup
74 for.cond.cleanup: ; preds = %for.body.epil, %for.cond.cleanup.loopexit.unr-lcssa, %entry
77 for.body: ; preds = %for.body, %for.body.preheader.new
78 %indvars.iv = phi i64 [ 0, %for.body.preheader.new ], [ %indvars.iv.next.1, %for.body ]
79 %niter = phi i64 [ 0, %for.body.preheader.new ], [ %niter.next.1, %for.body ]
80 %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv
81 %2 = load i32, ptr %arrayidx, align 4
82 %add = add nsw i32 %2, 4
83 store i32 %add, ptr %arrayidx, align 4
84 %indvars.iv.next = or i64 %indvars.iv, 1
85 %arrayidx.1 = getelementptr inbounds i32, ptr %a, i64 %indvars.iv.next
86 %3 = load i32, ptr %arrayidx.1, align 4
87 %add.1 = add nsw i32 %3, 4
88 store i32 %add.1, ptr %arrayidx.1, align 4
89 %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
90 %niter.next.1 = add i64 %niter, 2
91 %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
92 br i1 %niter.ncmp.1, label %for.cond.cleanup.loopexit.unr-lcssa, label %for.body
95 ; Make sure we do not change 4294967295 to -1 here.
96 define i64 @bug(i32 %x) {
98 ; CHECK-NEXT: [[A:%.*]] = sext i32 [[X:%.*]] to i64
99 ; CHECK-NEXT: [[B:%.*]] = and i64 [[A]], 4294967295
100 ; CHECK-NEXT: ret i64 [[B]]
102 %a = sext i32 %x to i64
103 %b = and i64 %a, 4294967295