1cee313d2SEric Christopher; RUN: opt -loop-versioning -S < %s | FileCheck %s 2cee313d2SEric Christopher 3cee313d2SEric Christopher; Make sure all PHIs are properly updated in the exit block. Based on 4cee313d2SEric Christopher; PR28037. 5cee313d2SEric Christopher 6cee313d2SEric Christophertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 7cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu" 8cee313d2SEric Christopher 9cee313d2SEric Christopher@x = external global [2 x [3 x [5 x i16]]] 10cee313d2SEric Christopher 11cee313d2SEric Christopher; CHECK-LABEL: @phi_with_undef 12cee313d2SEric Christopherdefine void @phi_with_undef() { 13cee313d2SEric Christopherbb6.lr.ph: ; preds = %bb5.preheader 14cee313d2SEric Christopher br label %bb6 15cee313d2SEric Christopher 16cee313d2SEric Christopherbb6: ; preds = %bb6.lr.ph, %bb6 17cee313d2SEric Christopher %_tmp1423 = phi i64 [ undef, %bb6.lr.ph ], [ %_tmp142, %bb6 ] 18cee313d2SEric Christopher %_tmp123 = getelementptr [2 x [3 x [5 x i16]]], [2 x [3 x [5 x i16]]]* @x, i16 0, i64 undef 19cee313d2SEric Christopher %_tmp126 = getelementptr [3 x [5 x i16]], [3 x [5 x i16]]* %_tmp123, i16 0, i64 %_tmp1423 20cee313d2SEric Christopher %_tmp129 = getelementptr [5 x i16], [5 x i16]* %_tmp126, i16 0, i64 undef 21cee313d2SEric Christopher %_tmp130 = load i16, i16* %_tmp129 22cee313d2SEric Christopher store i16 undef, i16* getelementptr ([2 x [3 x [5 x i16]]], [2 x [3 x [5 x i16]]]* @x, i64 0, i64 undef, i64 undef, i64 undef) 23cee313d2SEric Christopher %_tmp142 = add i64 %_tmp1423, 1 24cee313d2SEric Christopher br i1 false, label %bb6, label %loop.exit 25cee313d2SEric Christopher 26cee313d2SEric Christopherloop.exit: ; preds = %bb6 27cee313d2SEric Christopher %_tmp142.lcssa = phi i64 [ %_tmp142, %bb6 ] 28cee313d2SEric Christopher %split = phi i16 [ undef, %bb6 ] 29*060a4fccSTaWeiTu; CHECK: %split.ph = phi i16 [ undef, %bb6.lver.orig ] 30*060a4fccSTaWeiTu; CHECK: %split.ph3 = phi i16 [ undef, %bb6 ] 31*060a4fccSTaWeiTu; CHECK: %split = phi i16 [ %split.ph, %loop.exit.loopexit ], [ %split.ph3, %loop.exit.loopexit1 ] 32cee313d2SEric Christopher br label %bb9 33cee313d2SEric Christopher 34cee313d2SEric Christopherbb9: ; preds = %bb9.loopexit, %bb1 35cee313d2SEric Christopher ret void 36cee313d2SEric Christopher} 37cee313d2SEric Christopher 38cee313d2SEric Christopher; CHECK-LABEL: @phi_with_non_loop_defined_value 39cee313d2SEric Christopherdefine void @phi_with_non_loop_defined_value() { 40cee313d2SEric Christopherbb6.lr.ph: ; preds = %bb5.preheader 41cee313d2SEric Christopher %t = add i16 1, 1 42cee313d2SEric Christopher br label %bb6 43cee313d2SEric Christopher 44cee313d2SEric Christopherbb6: ; preds = %bb6.lr.ph, %bb6 45cee313d2SEric Christopher %_tmp1423 = phi i64 [ undef, %bb6.lr.ph ], [ %_tmp142, %bb6 ] 46cee313d2SEric Christopher %_tmp123 = getelementptr [2 x [3 x [5 x i16]]], [2 x [3 x [5 x i16]]]* @x, i16 0, i64 undef 47cee313d2SEric Christopher %_tmp126 = getelementptr [3 x [5 x i16]], [3 x [5 x i16]]* %_tmp123, i16 0, i64 %_tmp1423 48cee313d2SEric Christopher %_tmp129 = getelementptr [5 x i16], [5 x i16]* %_tmp126, i16 0, i64 undef 49cee313d2SEric Christopher %_tmp130 = load i16, i16* %_tmp129 50cee313d2SEric Christopher store i16 undef, i16* getelementptr ([2 x [3 x [5 x i16]]], [2 x [3 x [5 x i16]]]* @x, i64 0, i64 undef, i64 undef, i64 undef) 51cee313d2SEric Christopher %_tmp142 = add i64 %_tmp1423, 1 52cee313d2SEric Christopher br i1 false, label %bb6, label %loop.exit 53cee313d2SEric Christopher 54cee313d2SEric Christopherloop.exit: ; preds = %bb6 55cee313d2SEric Christopher %_tmp142.lcssa = phi i64 [ %_tmp142, %bb6 ] 56cee313d2SEric Christopher %split = phi i16 [ %t, %bb6 ] 57*060a4fccSTaWeiTu; CHECK: %split.ph = phi i16 [ %t, %bb6.lver.orig ] 58*060a4fccSTaWeiTu; CHECK: %split.ph3 = phi i16 [ %t, %bb6 ] 59*060a4fccSTaWeiTu; CHECK: %split = phi i16 [ %split.ph, %loop.exit.loopexit ], [ %split.ph3, %loop.exit.loopexit1 ] 60cee313d2SEric Christopher br label %bb9 61cee313d2SEric Christopher 62cee313d2SEric Christopherbb9: ; preds = %bb9.loopexit, %bb1 63cee313d2SEric Christopher ret void 64cee313d2SEric Christopher} 65