124 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt -S -loop-reduce %s | FileCheck %s3; REQUIRES: x86-registered-target4 5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"6target triple = "x86_64-unknown-linux-gnu"7 8define i64 @test_duplicated_phis(i64 noundef %N) {9; CHECK-LABEL: define i64 @test_duplicated_phis(10; CHECK-SAME: i64 noundef [[N:%.*]]) {11; CHECK-NEXT: [[ENTRY:.*]]:12; CHECK-NEXT: [[MUL:%.*]] = shl i64 [[N]], 113; CHECK-NEXT: [[CMP6_NOT:%.*]] = icmp eq i64 [[MUL]], 014; CHECK-NEXT: br i1 [[CMP6_NOT]], label %[[FOR_END:.*]], label %[[FOR_BODY_PREHEADER:.*]]15; CHECK: [[FOR_BODY_PREHEADER]]:16; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i64 [[MUL]], 417; CHECK-NEXT: br i1 [[TMP0]], label %[[FOR_END_LOOPEXIT_UNR_LCSSA:.*]], label %[[FOR_BODY_PREHEADER_NEW:.*]]18; CHECK: [[FOR_BODY_PREHEADER_NEW]]:19; CHECK-NEXT: [[UNROLL_ITER:%.*]] = and i64 [[MUL]], -420; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[UNROLL_ITER]], -421; CHECK-NEXT: [[TMP3:%.*]] = lshr i64 [[TMP4]], 122; CHECK-NEXT: [[LSR_IV_NEXT:%.*]] = sub i64 -3, [[TMP3]]23; CHECK-NEXT: br label %[[FOR_BODY:.*]]24; CHECK: [[FOR_BODY]]:25; CHECK-NEXT: [[I_07:%.*]] = phi i64 [ 0, %[[FOR_BODY_PREHEADER_NEW]] ], [ [[INC_3:%.*]], %[[FOR_BODY]] ]26; CHECK-NEXT: [[INC_3]] = add i64 [[I_07]], 427; CHECK-NEXT: [[NITER_NCMP_3_NOT:%.*]] = icmp eq i64 [[UNROLL_ITER]], [[INC_3]]28; CHECK-NEXT: br i1 [[NITER_NCMP_3_NOT]], label %[[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT:.*]], label %[[FOR_BODY]]29; CHECK: [[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT]]:30; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[LSR_IV_NEXT]], 131; CHECK-NEXT: br label %[[FOR_END_LOOPEXIT_UNR_LCSSA]]32; CHECK: [[FOR_END_LOOPEXIT_UNR_LCSSA]]:33; CHECK-NEXT: [[RES_1_LCSSA_PH:%.*]] = phi i64 [ undef, %[[FOR_BODY_PREHEADER]] ], [ [[TMP1]], %[[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ]34; CHECK-NEXT: [[RES_09_UNR:%.*]] = phi i64 [ -1, %[[FOR_BODY_PREHEADER]] ], [ [[LSR_IV_NEXT]], %[[FOR_END_LOOPEXIT_UNR_LCSSA_LOOPEXIT]] ]35; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[N]], 136; CHECK-NEXT: [[LCMP_MOD_NOT:%.*]] = icmp eq i64 [[TMP2]], 037; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[LCMP_MOD_NOT]], i64 [[RES_1_LCSSA_PH]], i64 [[RES_09_UNR]]38; CHECK-NEXT: br label %[[FOR_END]]39; CHECK: [[FOR_END]]:40; CHECK-NEXT: [[RES_0_LCSSA:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[SPEC_SELECT]], %[[FOR_END_LOOPEXIT_UNR_LCSSA]] ]41; CHECK-NEXT: ret i64 [[RES_0_LCSSA]]42;43entry:44 %mul = shl i64 %N, 145 %cmp6.not = icmp eq i64 %mul, 046 br i1 %cmp6.not, label %for.end, label %for.body.preheader47 48for.body.preheader:49 %0 = icmp ult i64 %mul, 450 br i1 %0, label %for.end.loopexit.unr-lcssa, label %for.body.preheader.new51 52for.body.preheader.new:53 %unroll_iter = and i64 %mul, -454 br label %for.body55 56for.body:57 %res.09 = phi i64 [ 0, %for.body.preheader.new ], [ %res.1.3, %for.body ]58 %i.07 = phi i64 [ 0, %for.body.preheader.new ], [ %inc.3, %for.body ]59 %niter = phi i64 [ 0, %for.body.preheader.new ], [ %niter.next.3, %for.body ]60 %res.1.1 = add i64 %res.09, -161 %inc.1 = or disjoint i64 %i.07, 262 %res.1.2 = add i64 %inc.1, %res.1.163 %reass.sub = sub i64 %res.1.2, %i.0764 %res.1.3 = add i64 %reass.sub, -365 %inc.3 = add nuw i64 %i.07, 466 %niter.next.3 = add i64 %niter, 467 %niter.ncmp.3.not = icmp eq i64 %niter.next.3, %unroll_iter68 br i1 %niter.ncmp.3.not, label %for.end.loopexit.unr-lcssa.loopexit, label %for.body69 70for.end.loopexit.unr-lcssa.loopexit:71 %1 = add i64 %reass.sub, -472 br label %for.end.loopexit.unr-lcssa73 74for.end.loopexit.unr-lcssa:75 %res.1.lcssa.ph = phi i64 [ undef, %for.body.preheader ], [ %res.1.3, %for.end.loopexit.unr-lcssa.loopexit ]76 %res.09.unr = phi i64 [ -1, %for.body.preheader ], [ %1, %for.end.loopexit.unr-lcssa.loopexit ]77 %2 = and i64 %N, 178 %lcmp.mod.not = icmp eq i64 %2, 079 %spec.select = select i1 %lcmp.mod.not, i64 %res.1.lcssa.ph, i64 %res.09.unr80 br label %for.end81 82for.end:83 %res.0.lcssa = phi i64 [ 0, %entry ], [ %spec.select, %for.end.loopexit.unr-lcssa ]84 ret i64 %res.0.lcssa85}86 87define i64 @duplicated_phis_compare_uses_mul_udiv(i64 %x) {88; CHECK-LABEL: define i64 @duplicated_phis_compare_uses_mul_udiv(89; CHECK-SAME: i64 [[X:%.*]]) {90; CHECK-NEXT: [[ENTRY:.*]]:91; CHECK-NEXT: [[MUL_2:%.*]] = shl i64 [[X]], 192; CHECK-NEXT: [[DIV_16:%.*]] = lshr i64 [[MUL_2]], 493; CHECK-NEXT: [[MASKED:%.*]] = and i64 [[DIV_16]], 115292150460684697494; CHECK-NEXT: br label %[[LOOP:.*]]95; CHECK: [[LOOP]]:96; CHECK-NEXT: [[IV_1:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_1_NEXT:%.*]], %[[LOOP]] ]97; CHECK-NEXT: call void @clobber()98; CHECK-NEXT: [[IV_1_NEXT]] = add i64 [[IV_1]], 299; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[MASKED]], [[IV_1_NEXT]]100; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]101; CHECK: [[EXIT]]:102; CHECK-NEXT: ret i64 [[IV_1_NEXT]]103;104entry:105 %mul.2 = shl i64 %x, 1106 %div.16 = lshr exact i64 %mul.2, 4107 %masked = and i64 %div.16, 1152921504606846974108 br label %loop109 110loop:111 %iv.1 = phi i64 [ 0, %entry ], [ %iv.1.next, %loop ]112 %iv.2 = phi i64 [ 0, %entry ], [ %iv.2.next, %loop ]113 call void @clobber()114 %iv.1.next = add i64 %iv.1, 2115 %iv.2.next = add i64 %iv.2, 2116 %ec = icmp eq i64 %iv.2.next, %masked117 br i1 %ec, label %exit, label %loop118 119exit:120 ret i64 %iv.1.next121}122 123declare void @clobber()124