1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -basic-aa -gvn -enable-load-pre -S | FileCheck %s 3; RUN: opt < %s -aa-pipeline=basic-aa -passes=gvn -enable-load-pre -S | FileCheck %s 4; RUN: opt < %s -aa-pipeline=basic-aa -passes="gvn<load-pre>" -enable-load-pre=false -S | FileCheck %s 5 6target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" 7target triple = "aarch64--linux-gnu" 8 9define double @foo(i32 %stat, i32 %i, double** %p) { 10; CHECK-LABEL: @foo( 11; CHECK-NEXT: entry: 12; CHECK-NEXT: switch i32 [[STAT:%.*]], label [[SW_DEFAULT:%.*]] [ 13; CHECK-NEXT: i32 0, label [[SW_BB:%.*]] 14; CHECK-NEXT: i32 1, label [[SW_BB]] 15; CHECK-NEXT: i32 2, label [[ENTRY_SW_BB2_CRIT_EDGE:%.*]] 16; CHECK-NEXT: ] 17; CHECK: entry.sw.bb2_crit_edge: 18; CHECK-NEXT: [[DOTPRE:%.*]] = load double*, double** [[P:%.*]], align 8 19; CHECK-NEXT: [[DOTPRE1:%.*]] = sext i32 [[I:%.*]] to i64 20; CHECK-NEXT: [[ARRAYIDX5_PHI_TRANS_INSERT:%.*]] = getelementptr inbounds double, double* [[DOTPRE]], i64 [[DOTPRE1]] 21; CHECK-NEXT: [[DOTPRE2:%.*]] = load double, double* [[ARRAYIDX5_PHI_TRANS_INSERT]], align 8 22; CHECK-NEXT: br label [[SW_BB2:%.*]] 23; CHECK: sw.bb: 24; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[I]] to i64 25; CHECK-NEXT: [[TMP0:%.*]] = load double*, double** [[P]], align 8 26; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds double, double* [[TMP0]], i64 [[IDXPROM]] 27; CHECK-NEXT: [[TMP1:%.*]] = load double, double* [[ARRAYIDX1]], align 8 28; CHECK-NEXT: [[SUB:%.*]] = fsub double [[TMP1]], 1.000000e+00 29; CHECK-NEXT: [[CMP:%.*]] = fcmp olt double [[SUB]], 0.000000e+00 30; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]] 31; CHECK: if.then: 32; CHECK-NEXT: br label [[RETURN:%.*]] 33; CHECK: if.end: 34; CHECK-NEXT: br label [[SW_BB2]] 35; CHECK: sw.bb2: 36; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[DOTPRE2]], [[ENTRY_SW_BB2_CRIT_EDGE]] ], [ [[TMP1]], [[IF_END]] ] 37; CHECK-NEXT: [[IDXPROM3_PRE_PHI:%.*]] = phi i64 [ [[DOTPRE1]], [[ENTRY_SW_BB2_CRIT_EDGE]] ], [ [[IDXPROM]], [[IF_END]] ] 38; CHECK-NEXT: [[TMP3:%.*]] = phi double* [ [[DOTPRE]], [[ENTRY_SW_BB2_CRIT_EDGE]] ], [ [[TMP0]], [[IF_END]] ] 39; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds double, double* [[TMP3]], i64 [[IDXPROM3_PRE_PHI]] 40; CHECK-NEXT: [[SUB6:%.*]] = fsub double 3.000000e+00, [[TMP2]] 41; CHECK-NEXT: store double [[SUB6]], double* [[ARRAYIDX5]] 42; CHECK-NEXT: br label [[RETURN]] 43; CHECK: sw.default: 44; CHECK-NEXT: br label [[RETURN]] 45; CHECK: return: 46; CHECK-NEXT: [[RETVAL_0:%.*]] = phi double [ 0.000000e+00, [[SW_DEFAULT]] ], [ [[SUB6]], [[SW_BB2]] ], [ [[SUB]], [[IF_THEN]] ] 47; CHECK-NEXT: ret double [[RETVAL_0]] 48; 49entry: 50 switch i32 %stat, label %sw.default [ 51 i32 0, label %sw.bb 52 i32 1, label %sw.bb 53 i32 2, label %sw.bb2 54 ] 55 56sw.bb: ; preds = %entry, %entry 57 %idxprom = sext i32 %i to i64 58 %arrayidx = getelementptr inbounds double*, double** %p, i64 0 59 %0 = load double*, double** %arrayidx, align 8 60 %arrayidx1 = getelementptr inbounds double, double* %0, i64 %idxprom 61 %1 = load double, double* %arrayidx1, align 8 62 %sub = fsub double %1, 1.000000e+00 63 %cmp = fcmp olt double %sub, 0.000000e+00 64 br i1 %cmp, label %if.then, label %if.end 65 66if.then: ; preds = %sw.bb 67 br label %return 68 69if.end: ; preds = %sw.bb 70 br label %sw.bb2 71 72sw.bb2: ; preds = %if.end, %entry 73 %idxprom3 = sext i32 %i to i64 74 %arrayidx4 = getelementptr inbounds double*, double** %p, i64 0 75 %2 = load double*, double** %arrayidx4, align 8 76 %arrayidx5 = getelementptr inbounds double, double* %2, i64 %idxprom3 77 %3 = load double, double* %arrayidx5, align 8 78 %sub6 = fsub double 3.000000e+00, %3 79 store double %sub6, double* %arrayidx5 80 br label %return 81 82sw.default: ; preds = %entry 83 br label %return 84 85return: ; preds = %sw.default, %sw.bb2, %if.then 86 %retval.0 = phi double [ 0.000000e+00, %sw.default ], [ %sub6, %sw.bb2 ], [ %sub, %if.then ] 87 ret double %retval.0 88} 89 90; The load causes the GEP's operands to be PREd earlier than normal. The 91; resulting sext ends up in pre.dest and in the GVN system before that BB is 92; actually processed. Make sure we can deal with the situation. 93 94define void @test_shortcut_safe(i1 %tst, i32 %p1, i32* %a) { 95; CHECK-LABEL: @test_shortcut_safe( 96; CHECK-NEXT: br i1 [[TST:%.*]], label [[SEXT1:%.*]], label [[DOTPRE_DEST_CRIT_EDGE:%.*]] 97; CHECK: .pre.dest_crit_edge: 98; CHECK-NEXT: [[DOTPRE1:%.*]] = sext i32 [[P1:%.*]] to i64 99; CHECK-NEXT: br label [[PRE_DEST:%.*]] 100; CHECK: pre.dest: 101; CHECK-NEXT: [[DOTPRE_PRE_PHI:%.*]] = phi i64 [ [[DOTPRE1]], [[DOTPRE_DEST_CRIT_EDGE]] ], [ [[IDXPROM2_PRE_PHI:%.*]], [[SEXT_USE:%.*]] ] 102; CHECK-NEXT: br label [[SEXT_USE]] 103; CHECK: sext1: 104; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[P1]] to i64 105; CHECK-NEXT: br label [[SEXT_USE]] 106; CHECK: sext.use: 107; CHECK-NEXT: [[IDXPROM2_PRE_PHI]] = phi i64 [ [[IDXPROM]], [[SEXT1]] ], [ [[DOTPRE_PRE_PHI]], [[PRE_DEST]] ] 108; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[IDXPROM2_PRE_PHI]] 109; CHECK-NEXT: [[VAL:%.*]] = load i32, i32* [[ARRAYIDX3]], align 4 110; CHECK-NEXT: tail call void @g(i32 [[VAL]]) 111; CHECK-NEXT: br label [[PRE_DEST]] 112; 113 114 br i1 %tst, label %sext1, label %pre.dest 115 116pre.dest: 117 br label %sext.use 118 119sext1: 120 %idxprom = sext i32 %p1 to i64 121 br label %sext.use 122 123sext.use: 124 %idxprom2 = sext i32 %p1 to i64 125 %arrayidx3 = getelementptr inbounds i32, i32* %a, i64 %idxprom2 126 %val = load i32, i32* %arrayidx3, align 4 127 tail call void (i32) @g(i32 %val) 128 br label %pre.dest 129} 130 131declare void @g(i32) 132