1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 2; RUN: opt < %s -passes=loop-versioning -S -o - | FileCheck %s 3 4; This test case used to end like this: 5; 6; Instruction does not dominate all uses! 7; %t2 = load i16, i16* @b, align 1, !tbaa !2, !alias.scope !6 8; %tobool = icmp eq i16 %t2, 0 9; LLVM ERROR: Broken function found, compilation aborted! 10; 11; due to a fault where we did not replace the use of %t2 in the icmp in 12; for.end, when adding a new PHI node for the versioned loops based on the 13; loop-defined values used outside of the loop. 14; 15; Verify that the code compiles, that we get a versioned loop, and that the 16; uses of %t2 in for.end and if.then are updated to use the value from the 17; added phi node. 18 19@a = dso_local global i16 0, align 1 20@b = dso_local global i16 0, align 1 21@c = dso_local global ptr null, align 1 22 23define void @f1() { 24; CHECK-LABEL: define void @f1() { 25; CHECK-NEXT: entry: 26; CHECK-NEXT: [[T0:%.*]] = load ptr, ptr @c, align 1 27; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[T0]], i64 2 28; CHECK-NEXT: br label [[FOR_BODY_LVER_CHECK:%.*]] 29; CHECK: for.body.lver.check: 30; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[T0]], getelementptr inbounds nuw (i8, ptr @b, i64 2) 31; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr @b, [[SCEVGEP]] 32; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]] 33; CHECK-NEXT: br i1 [[FOUND_CONFLICT]], label [[FOR_BODY_PH_LVER_ORIG:%.*]], label [[FOR_BODY_PH:%.*]] 34; CHECK: for.body.ph.lver.orig: 35; CHECK-NEXT: br label [[FOR_BODY_LVER_ORIG:%.*]] 36; CHECK: for.body.lver.orig: 37; CHECK-NEXT: [[T1_LVER_ORIG:%.*]] = phi i64 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[INC_LVER_ORIG:%.*]], [[FOR_BODY_LVER_ORIG]] ] 38; CHECK-NEXT: [[T2_LVER_ORIG:%.*]] = load i16, ptr @b, align 1, !tbaa [[TBAA2:![0-9]+]] 39; CHECK-NEXT: store i16 [[T2_LVER_ORIG]], ptr [[T0]], align 1, !tbaa [[TBAA2]] 40; CHECK-NEXT: [[INC_LVER_ORIG]] = add nuw nsw i64 [[T1_LVER_ORIG]], 1 41; CHECK-NEXT: [[CMP_LVER_ORIG:%.*]] = icmp ult i64 [[INC_LVER_ORIG]], 3 42; CHECK-NEXT: br i1 [[CMP_LVER_ORIG]], label [[FOR_BODY_LVER_ORIG]], label [[FOR_END_LOOPEXIT:%.*]] 43; CHECK: for.body.ph: 44; CHECK-NEXT: br label [[FOR_BODY:%.*]] 45; CHECK: for.body: 46; CHECK-NEXT: [[T1:%.*]] = phi i64 [ 0, [[FOR_BODY_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ] 47; CHECK-NEXT: [[T2:%.*]] = load i16, ptr @b, align 1, !tbaa [[TBAA2]], !alias.scope [[META6:![0-9]+]] 48; CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 1, !tbaa [[TBAA2]], !alias.scope [[META9:![0-9]+]], !noalias [[META6]] 49; CHECK-NEXT: [[INC]] = add nuw nsw i64 [[T1]], 1 50; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[INC]], 3 51; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT1:%.*]] 52; CHECK: for.end.loopexit: 53; CHECK-NEXT: [[T2_LVER_PH:%.*]] = phi i16 [ [[T2_LVER_ORIG]], [[FOR_BODY_LVER_ORIG]] ] 54; CHECK-NEXT: br label [[FOR_END:%.*]] 55; CHECK: for.end.loopexit1: 56; CHECK-NEXT: [[T2_LVER_PH2:%.*]] = phi i16 [ [[T2]], [[FOR_BODY]] ] 57; CHECK-NEXT: br label [[FOR_END]] 58; CHECK: for.end: 59; CHECK-NEXT: [[T2_LVER:%.*]] = phi i16 [ [[T2_LVER_PH]], [[FOR_END_LOOPEXIT]] ], [ [[T2_LVER_PH2]], [[FOR_END_LOOPEXIT1]] ] 60; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[T2_LVER]], 0 61; CHECK-NEXT: br i1 [[TOBOOL]], label [[FOR_COND_BACKEDGE:%.*]], label [[IF_THEN:%.*]] 62; CHECK: for.cond.backedge: 63; CHECK-NEXT: br label [[FOR_BODY_LVER_CHECK]] 64; CHECK: if.then: 65; CHECK-NEXT: store i16 [[T2_LVER]], ptr @a, align 1, !tbaa [[TBAA2]] 66; CHECK-NEXT: br label [[FOR_COND_BACKEDGE]] 67; 68entry: 69 %t0 = load ptr, ptr @c, align 1 70 br label %for.cond 71 72for.cond: ; preds = %for.cond.backedge, %entry 73 br label %for.body 74 75for.body: ; preds = %for.cond, %for.body 76 %t1 = phi i64 [ 0, %for.cond ], [ %inc, %for.body ] 77 %t2 = load i16, ptr @b, align 1, !tbaa !2 78 store i16 %t2, ptr %t0, align 1, !tbaa !2 79 %inc = add nuw nsw i64 %t1, 1 80 %cmp = icmp ult i64 %inc, 3 81 br i1 %cmp, label %for.body, label %for.end 82 83for.end: ; preds = %for.body 84 %tobool = icmp eq i16 %t2, 0 85 br i1 %tobool, label %for.cond.backedge, label %if.then 86 87for.cond.backedge: ; preds = %for.end, %if.then 88 br label %for.cond 89 90if.then: ; preds = %for.end 91 store i16 %t2, ptr @a, align 1, !tbaa !2 92 br label %for.cond.backedge 93} 94 95!llvm.module.flags = !{!0} 96!llvm.ident = !{!1} 97 98!0 = !{i32 1, !"wchar_size", i32 1} 99!1 = !{!"clang version 7.0.0"} 100!2 = !{!3, !3, i64 0} 101!3 = !{!"long long", !4, i64 0} 102!4 = !{!"omnipotent char", !5, i64 0} 103!5 = !{!"Simple C/C++ TBAA"} 104