1cee313d2SEric Christopher; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2cee313d2SEric Christopher; RUN: opt -loop-reduce -S < %s | FileCheck %s 3cee313d2SEric Christopher 4cee313d2SEric Christopher; Check when we use an outerloop induction variable inside of an innerloop 5cee313d2SEric Christopher; induction value expr, LSR can still choose to use single induction variable 6cee313d2SEric Christopher; for the innerloop and share it in multiple induction value exprs. 7cee313d2SEric Christopher 8cee313d2SEric Christophertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 9cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu" 10cee313d2SEric Christopher 11cee313d2SEric Christopherdefine void @foo(i32 %size, i32 %nsteps, i32 %hsize, i32* %lined, i8* %maxarray) { 12cee313d2SEric Christopher; CHECK-LABEL: @foo( 13cee313d2SEric Christopher; CHECK-NEXT: entry: 14cee313d2SEric Christopher; CHECK-NEXT: [[CMP215:%.*]] = icmp sgt i32 [[SIZE:%.*]], 1 15cee313d2SEric Christopher; CHECK-NEXT: [[T0:%.*]] = zext i32 [[SIZE]] to i64 16cee313d2SEric Christopher; CHECK-NEXT: [[T1:%.*]] = sext i32 [[NSTEPS:%.*]] to i64 170cf9639aSSam Parker; CHECK-NEXT: [[TMP0:%.*]] = add nsw i64 [[T0]], -1 18cee313d2SEric Christopher; CHECK-NEXT: br label [[FOR_BODY:%.*]] 19cee313d2SEric Christopher; CHECK: for.body: 20cee313d2SEric Christopher; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i64 [ [[LSR_IV_NEXT2:%.*]], [[FOR_INC:%.*]] ], [ 1, [[ENTRY:%.*]] ] 21cee313d2SEric Christopher; CHECK-NEXT: [[INDVARS_IV2:%.*]] = phi i64 [ [[INDVARS_IV_NEXT3:%.*]], [[FOR_INC]] ], [ 0, [[ENTRY]] ] 22cee313d2SEric Christopher; CHECK-NEXT: br i1 [[CMP215]], label [[FOR_BODY2_PREHEADER:%.*]], label [[FOR_INC]] 23cee313d2SEric Christopher; CHECK: for.body2.preheader: 24cee313d2SEric Christopher; CHECK-NEXT: br label [[FOR_BODY2:%.*]] 25cee313d2SEric Christopher; CHECK: for.body2: 26cee313d2SEric Christopher; CHECK-NEXT: [[LSR_IV3:%.*]] = phi i8* [ [[SCEVGEP:%.*]], [[FOR_BODY2]] ], [ [[MAXARRAY:%.*]], [[FOR_BODY2_PREHEADER]] ] 27cee313d2SEric Christopher; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[FOR_BODY2]] ], [ [[TMP0]], [[FOR_BODY2_PREHEADER]] ] 28cee313d2SEric Christopher; CHECK-NEXT: [[SCEVGEP6:%.*]] = getelementptr i8, i8* [[LSR_IV3]], i64 1 29cee313d2SEric Christopher; CHECK-NEXT: [[V1:%.*]] = load i8, i8* [[SCEVGEP6]], align 1 30cee313d2SEric Christopher; CHECK-NEXT: [[SCEVGEP5:%.*]] = getelementptr i8, i8* [[LSR_IV3]], i64 [[TMP0]] 31cee313d2SEric Christopher; CHECK-NEXT: [[V2:%.*]] = load i8, i8* [[SCEVGEP5]], align 1 32cee313d2SEric Christopher; CHECK-NEXT: [[TMPV:%.*]] = xor i8 [[V1]], [[V2]] 33cee313d2SEric Christopher; CHECK-NEXT: [[SCEVGEP4:%.*]] = getelementptr i8, i8* [[LSR_IV3]], i64 [[LSR_IV1]] 34cee313d2SEric Christopher; CHECK-NEXT: store i8 [[TMPV]], i8* [[SCEVGEP4]], align 1 35*aa58fdb3SFlorian Hahn; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], -1 36cee313d2SEric Christopher; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, i8* [[LSR_IV3]], i64 1 37cee313d2SEric Christopher; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[LSR_IV_NEXT]], 0 38cee313d2SEric Christopher; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY2]], label [[FOR_INC_LOOPEXIT:%.*]] 39cee313d2SEric Christopher; CHECK: for.inc.loopexit: 40cee313d2SEric Christopher; CHECK-NEXT: br label [[FOR_INC]] 41cee313d2SEric Christopher; CHECK: for.inc: 42cee313d2SEric Christopher; CHECK-NEXT: [[INDVARS_IV_NEXT3]] = add nuw nsw i64 [[INDVARS_IV2]], 1 43cee313d2SEric Christopher; CHECK-NEXT: [[LSR_IV_NEXT2]] = add nuw nsw i64 [[LSR_IV1]], [[T0]] 44cee313d2SEric Christopher; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[INDVARS_IV_NEXT3]], [[T1]] 45cee313d2SEric Christopher; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] 46cee313d2SEric Christopher; CHECK: for.end.loopexit: 47cee313d2SEric Christopher; CHECK-NEXT: ret void 48cee313d2SEric Christopher; 49cee313d2SEric Christopherentry: 50cee313d2SEric Christopher %cmp215 = icmp sgt i32 %size, 1 51cee313d2SEric Christopher %t0 = zext i32 %size to i64 52cee313d2SEric Christopher %t1 = sext i32 %nsteps to i64 53cee313d2SEric Christopher %sub2 = sub i64 %t0, 2 54cee313d2SEric Christopher br label %for.body 55cee313d2SEric Christopher 56cee313d2SEric Christopherfor.body: ; preds = %for.inc, %entry 57cee313d2SEric Christopher %indvars.iv2 = phi i64 [ %indvars.iv.next3, %for.inc ], [ 0, %entry ] 58cee313d2SEric Christopher %t2 = mul nsw i64 %indvars.iv2, %t0 59cee313d2SEric Christopher br i1 %cmp215, label %for.body2.preheader, label %for.inc 60cee313d2SEric Christopher 61cee313d2SEric Christopherfor.body2.preheader: ; preds = %for.body 62cee313d2SEric Christopher br label %for.body2 63cee313d2SEric Christopher 64cee313d2SEric Christopher; Check LSR only generates two induction variables for for.body2 one for compare and 65cee313d2SEric Christopher; one to shared by multiple array accesses. 66cee313d2SEric Christopher 67cee313d2SEric Christopherfor.body2: ; preds = %for.body2.preheader, %for.body2 68cee313d2SEric Christopher %indvars.iv = phi i64 [ 1, %for.body2.preheader ], [ %indvars.iv.next, %for.body2 ] 69cee313d2SEric Christopher %arrayidx1 = getelementptr inbounds i8, i8* %maxarray, i64 %indvars.iv 70cee313d2SEric Christopher %v1 = load i8, i8* %arrayidx1, align 1 71cee313d2SEric Christopher %idx2 = add nsw i64 %indvars.iv, %sub2 72cee313d2SEric Christopher %arrayidx2 = getelementptr inbounds i8, i8* %maxarray, i64 %idx2 73cee313d2SEric Christopher %v2 = load i8, i8* %arrayidx2, align 1 74cee313d2SEric Christopher %tmpv = xor i8 %v1, %v2 75cee313d2SEric Christopher %t4 = add nsw i64 %t2, %indvars.iv 76cee313d2SEric Christopher %add.ptr = getelementptr inbounds i8, i8* %maxarray, i64 %t4 77cee313d2SEric Christopher store i8 %tmpv, i8* %add.ptr, align 1 78cee313d2SEric Christopher %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 79cee313d2SEric Christopher %wide.trip.count = zext i32 %size to i64 80cee313d2SEric Christopher %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count 81cee313d2SEric Christopher br i1 %exitcond, label %for.body2, label %for.inc.loopexit 82cee313d2SEric Christopher 83cee313d2SEric Christopherfor.inc.loopexit: ; preds = %for.body2 84cee313d2SEric Christopher br label %for.inc 85cee313d2SEric Christopher 86cee313d2SEric Christopherfor.inc: ; preds = %for.inc.loopexit, %for.body 87cee313d2SEric Christopher %indvars.iv.next3 = add nuw nsw i64 %indvars.iv2, 1 88cee313d2SEric Christopher %cmp = icmp slt i64 %indvars.iv.next3, %t1 89cee313d2SEric Christopher br i1 %cmp, label %for.body, label %for.end.loopexit 90cee313d2SEric Christopher 91cee313d2SEric Christopherfor.end.loopexit: ; preds = %for.inc 92cee313d2SEric Christopher ret void 93cee313d2SEric Christopher} 94