1; RUN: opt < %s -loop-versioning -S -o - | FileCheck %s 2 3; This test case used to end like this: 4; 5; Instruction does not dominate all uses! 6; %t2 = load i16, i16* @b, align 1, !tbaa !2, !alias.scope !6 7; %tobool = icmp eq i16 %t2, 0 8; LLVM ERROR: Broken function found, compilation aborted! 9; 10; due to a fault where we did not replace the use of %t2 in the icmp in 11; for.end, when adding a new PHI node for the versioned loops based on the 12; loop-defined values used outside of the loop. 13; 14; Verify that the code compiles, that we get a versioned loop, and that the 15; uses of %t2 in for.end and if.then are updated to use the value from the 16; added phi node. 17 18; CHECK: define void @f1 19; CHECK: for.end.loopexit: 20; CHECK-NEXT: %t2.lver.ph = phi i16 [ %t2.lver.orig, %for.body.lver.orig ] 21; CHECK: for.end.loopexit2: 22; CHECK-NEXT: %t2.lver.ph3 = phi i16 [ %t2, %for.body ] 23; CHECK: for.end: 24; CHECK-NEXT: %t2.lver = phi i16 [ %t2.lver.ph, %for.end.loopexit ], [ %t2.lver.ph3, %for.end.loopexit2 ] 25; CHECK-NEXT: %tobool = icmp eq i16 %t2.lver, 0 26; CHECK: if.then: 27; CHECK-NEXT: store i16 %t2.lver 28 29@a = dso_local global i16 0, align 1 30@b = dso_local global i16 0, align 1 31@c = dso_local global i16* null, align 1 32 33define void @f1() { 34entry: 35 %t0 = load i16*, i16** @c, align 1 36 br label %for.cond 37 38for.cond: ; preds = %for.cond.backedge, %entry 39 br label %for.body 40 41for.body: ; preds = %for.cond, %for.body 42 %t1 = phi i64 [ 0, %for.cond ], [ %inc, %for.body ] 43 %t2 = load i16, i16* @b, align 1, !tbaa !2 44 store i16 %t2, i16* %t0, align 1, !tbaa !2 45 %inc = add nuw nsw i64 %t1, 1 46 %cmp = icmp ult i64 %inc, 3 47 br i1 %cmp, label %for.body, label %for.end 48 49for.end: ; preds = %for.body 50 %tobool = icmp eq i16 %t2, 0 51 br i1 %tobool, label %for.cond.backedge, label %if.then 52 53for.cond.backedge: ; preds = %for.end, %if.then 54 br label %for.cond 55 56if.then: ; preds = %for.end 57 store i16 %t2, i16* @a, align 1, !tbaa !2 58 br label %for.cond.backedge 59} 60 61!llvm.module.flags = !{!0} 62!llvm.ident = !{!1} 63 64!0 = !{i32 1, !"wchar_size", i32 1} 65!1 = !{!"clang version 7.0.0"} 66!2 = !{!3, !3, i64 0} 67!3 = !{!"long long", !4, i64 0} 68!4 = !{!"omnipotent char", !5, i64 0} 69!5 = !{!"Simple C/C++ TBAA"} 70