1*9880d681SAndroid Build Coastguard Worker; RUN: opt -loop-reduce -S < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; 3*9880d681SAndroid Build Coastguard Worker; LTO of clang, which mistakenly uses no TargetLoweringInfo, causes a 4*9880d681SAndroid Build Coastguard Worker; miscompile. ReuseOrCreateCast replace ptrtoint operand with undef. 5*9880d681SAndroid Build Coastguard Worker; Reproducing the miscompile requires no triple, hence no "TTI". 6*9880d681SAndroid Build Coastguard Worker; rdar://13007381 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker; Verify that nothing uses the "dead" ptrtoint from "undef". 11*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @VerifyDiagnosticConsumerTest( 12*9880d681SAndroid Build Coastguard Worker; CHECK: bb: 13*9880d681SAndroid Build Coastguard Worker; "dead" ptrpoint not emitted (or dead code eliminated) with 14*9880d681SAndroid Build Coastguard Worker; current LSR cost model. 15*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: = ptrtoint i8* undef to i64 16*9880d681SAndroid Build Coastguard Worker; CHECK: .lr.ph 17*9880d681SAndroid Build Coastguard Worker; CHECK: [[TMP:%[^ ]+]] = add i64 %tmp5, 1 18*9880d681SAndroid Build Coastguard Worker; CHECK: sub i64 [[TMP]], %tmp6 19*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 20*9880d681SAndroid Build Coastguard Workerdefine void @VerifyDiagnosticConsumerTest() unnamed_addr nounwind uwtable align 2 { 21*9880d681SAndroid Build Coastguard Workerbb: 22*9880d681SAndroid Build Coastguard Worker %tmp3 = call i8* @getCharData() nounwind 23*9880d681SAndroid Build Coastguard Worker %tmp4 = call i8* @getCharData() nounwind 24*9880d681SAndroid Build Coastguard Worker %tmp5 = ptrtoint i8* %tmp4 to i64 25*9880d681SAndroid Build Coastguard Worker %tmp6 = ptrtoint i8* %tmp3 to i64 26*9880d681SAndroid Build Coastguard Worker %tmp7 = sub i64 %tmp5, %tmp6 27*9880d681SAndroid Build Coastguard Worker br i1 undef, label %bb87, label %.preheader 28*9880d681SAndroid Build Coastguard Worker 29*9880d681SAndroid Build Coastguard Worker.preheader: ; preds = %bb10, %bb 30*9880d681SAndroid Build Coastguard Worker br i1 undef, label %_ZNK4llvm9StringRef4findEcm.exit42.thread, label %bb10 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Workerbb10: ; preds = %.preheader 33*9880d681SAndroid Build Coastguard Worker br i1 undef, label %_ZNK4llvm9StringRef4findEcm.exit42, label %.preheader 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker_ZNK4llvm9StringRef4findEcm.exit42: ; preds = %bb10 36*9880d681SAndroid Build Coastguard Worker br i1 undef, label %_ZNK4llvm9StringRef4findEcm.exit42.thread, label %.lr.ph 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker_ZNK4llvm9StringRef4findEcm.exit42.thread: ; preds = %_ZNK4llvm9StringRef4findEcm.exit42, %.preheader 39*9880d681SAndroid Build Coastguard Worker unreachable 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker.lr.ph: ; preds = %_ZNK4llvm9StringRef4findEcm.exit42 42*9880d681SAndroid Build Coastguard Worker br label %bb36 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Worker_ZNK4llvm9StringRef4findEcm.exit.loopexit: ; preds = %bb63 45*9880d681SAndroid Build Coastguard Worker %tmp21 = icmp eq i64 %i.0.i, -1 46*9880d681SAndroid Build Coastguard Worker br i1 %tmp21, label %_ZNK4llvm9StringRef4findEcm.exit._crit_edge, label %bb36 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker_ZNK4llvm9StringRef4findEcm.exit._crit_edge: ; preds = %bb61, %_ZNK4llvm9StringRef4findEcm.exit.loopexit 49*9880d681SAndroid Build Coastguard Worker unreachable 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Workerbb36: ; preds = %_ZNK4llvm9StringRef4findEcm.exit.loopexit, %.lr.ph 52*9880d681SAndroid Build Coastguard Worker %loc.063 = phi i64 [ undef, %.lr.ph ], [ %i.0.i, %_ZNK4llvm9StringRef4findEcm.exit.loopexit ] 53*9880d681SAndroid Build Coastguard Worker switch i8 undef, label %bb57 [ 54*9880d681SAndroid Build Coastguard Worker i8 10, label %bb48 55*9880d681SAndroid Build Coastguard Worker i8 13, label %bb48 56*9880d681SAndroid Build Coastguard Worker ] 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Workerbb48: ; preds = %bb36, %bb36 59*9880d681SAndroid Build Coastguard Worker br label %bb58 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Workerbb57: ; preds = %bb36 62*9880d681SAndroid Build Coastguard Worker br label %bb58 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Workerbb58: ; preds = %bb57, %bb48 65*9880d681SAndroid Build Coastguard Worker %tmp59 = icmp ugt i64 %tmp7, undef 66*9880d681SAndroid Build Coastguard Worker %tmp60 = select i1 %tmp59, i64 undef, i64 %tmp7 67*9880d681SAndroid Build Coastguard Worker br label %bb61 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Workerbb61: ; preds = %bb63, %bb58 70*9880d681SAndroid Build Coastguard Worker %i.0.i = phi i64 [ %tmp60, %bb58 ], [ %tmp67, %bb63 ] 71*9880d681SAndroid Build Coastguard Worker %tmp62 = icmp eq i64 %i.0.i, %tmp7 72*9880d681SAndroid Build Coastguard Worker br i1 %tmp62, label %_ZNK4llvm9StringRef4findEcm.exit._crit_edge, label %bb63 73*9880d681SAndroid Build Coastguard Worker 74*9880d681SAndroid Build Coastguard Workerbb63: ; preds = %bb61 75*9880d681SAndroid Build Coastguard Worker %tmp64 = getelementptr inbounds i8, i8* %tmp3, i64 %i.0.i 76*9880d681SAndroid Build Coastguard Worker %tmp65 = load i8, i8* %tmp64, align 1 77*9880d681SAndroid Build Coastguard Worker %tmp67 = add i64 %i.0.i, 1 78*9880d681SAndroid Build Coastguard Worker br i1 undef, label %_ZNK4llvm9StringRef4findEcm.exit.loopexit, label %bb61 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Workerbb87: ; preds = %bb 81*9880d681SAndroid Build Coastguard Worker ret void 82*9880d681SAndroid Build Coastguard Worker} 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Workerdeclare i8* @getCharData() 85