99 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt < %s -passes=gvn -enable-load-pre -S | FileCheck %s --check-prefixes=CHECK,MDEP3; RUN: opt < %s -passes='gvn<memoryssa>' -enable-load-pre -S | FileCheck %s --check-prefixes=CHECK,MSSA4; RUN: opt < %s -passes="gvn<load-pre>" -enable-load-pre=false -S | FileCheck %s5; This testcase assumed we'll PRE the load into %for.cond, but we don't actually6; verify that doing so is safe. If there didn't _happen_ to be a load in7; %for.end, we would actually be lengthening the execution on some paths, and8; we were never actually checking that case. Now we actually do perform some9; conservative checking to make sure we don't make paths longer, but we don't10; currently get this case, which we got lucky on previously.11;12; Now that that faulty assumption is corrected, test that we DON'T incorrectly13; hoist the load. Doing the right thing for the wrong reasons is still a bug.14 15@p = external global i3216define i32 @f(i32 %n) nounwind {17; MDEP-LABEL: define i32 @f(18; MDEP-SAME: i32 [[N:%.*]]) #[[ATTR0:[0-9]+]] {19; MDEP-NEXT: [[ENTRY:.*]]:20; MDEP-NEXT: br label %[[FOR_COND:.*]]21; MDEP: [[FOR_COND]]:22; MDEP-NEXT: [[I_0:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[INDVAR_NEXT:%.*]], %[[FOR_INC:.*]] ]23; MDEP-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[N]]24; MDEP-NEXT: br i1 [[CMP]], label %[[FOR_BODY:.*]], label %[[FOR_COND_FOR_END_CRIT_EDGE:.*]]25; MDEP: [[FOR_COND_FOR_END_CRIT_EDGE]]:26; MDEP-NEXT: [[TMP9_PRE:%.*]] = load i32, ptr @p, align 427; MDEP-NEXT: br label %[[FOR_END:.*]]28; MDEP: [[FOR_BODY]]:29; MDEP-NEXT: [[TMP3:%.*]] = load i32, ptr @p, align 430; MDEP-NEXT: [[DEC:%.*]] = add i32 [[TMP3]], -131; MDEP-NEXT: store i32 [[DEC]], ptr @p, align 432; MDEP-NEXT: [[CMP6:%.*]] = icmp slt i32 [[DEC]], 033; MDEP-NEXT: br i1 [[CMP6]], label %[[FOR_BODY_FOR_END_CRIT_EDGE:.*]], label %[[FOR_INC]]34; MDEP: [[FOR_BODY_FOR_END_CRIT_EDGE]]:35; MDEP-NEXT: br label %[[FOR_END]]36; MDEP: [[FOR_INC]]:37; MDEP-NEXT: [[INDVAR_NEXT]] = add i32 [[I_0]], 138; MDEP-NEXT: br label %[[FOR_COND]]39; MDEP: [[FOR_END]]:40; MDEP-NEXT: [[TMP9:%.*]] = phi i32 [ [[DEC]], %[[FOR_BODY_FOR_END_CRIT_EDGE]] ], [ [[TMP9_PRE]], %[[FOR_COND_FOR_END_CRIT_EDGE]] ]41; MDEP-NEXT: ret i32 [[TMP9]]42;43; MSSA-LABEL: define i32 @f(44; MSSA-SAME: i32 [[N:%.*]]) #[[ATTR0:[0-9]+]] {45; MSSA-NEXT: [[ENTRY:.*]]:46; MSSA-NEXT: br label %[[FOR_COND:.*]]47; MSSA: [[FOR_COND]]:48; MSSA-NEXT: [[I_0:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[INDVAR_NEXT:%.*]], %[[FOR_INC:.*]] ]49; MSSA-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[N]]50; MSSA-NEXT: br i1 [[CMP]], label %[[FOR_BODY:.*]], label %[[FOR_COND_FOR_END_CRIT_EDGE:.*]]51; MSSA: [[FOR_COND_FOR_END_CRIT_EDGE]]:52; MSSA-NEXT: br label %[[FOR_END:.*]]53; MSSA: [[FOR_BODY]]:54; MSSA-NEXT: [[TMP3:%.*]] = load i32, ptr @p, align 455; MSSA-NEXT: [[DEC:%.*]] = add i32 [[TMP3]], -156; MSSA-NEXT: store i32 [[DEC]], ptr @p, align 457; MSSA-NEXT: [[CMP6:%.*]] = icmp slt i32 [[DEC]], 058; MSSA-NEXT: br i1 [[CMP6]], label %[[FOR_BODY_FOR_END_CRIT_EDGE:.*]], label %[[FOR_INC]]59; MSSA: [[FOR_BODY_FOR_END_CRIT_EDGE]]:60; MSSA-NEXT: br label %[[FOR_END]]61; MSSA: [[FOR_INC]]:62; MSSA-NEXT: [[INDVAR_NEXT]] = add i32 [[I_0]], 163; MSSA-NEXT: br label %[[FOR_COND]]64; MSSA: [[FOR_END]]:65; MSSA-NEXT: [[TMP9:%.*]] = load i32, ptr @p, align 466; MSSA-NEXT: ret i32 [[TMP9]]67;68entry:69 br label %for.cond70 71for.cond: ; preds = %for.inc, %entry72 %i.0 = phi i32 [ 0, %entry ], [ %indvar.next, %for.inc ] ; <i32> [#uses=2]73 %cmp = icmp slt i32 %i.0, %n ; <i1> [#uses=1]74 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge75 76for.cond.for.end_crit_edge: ; preds = %for.cond77 br label %for.end78 79for.body: ; preds = %for.cond80 %tmp3 = load i32, ptr @p ; <i32> [#uses=1]81 %dec = add i32 %tmp3, -1 ; <i32> [#uses=2]82 store i32 %dec, ptr @p83 %cmp6 = icmp slt i32 %dec, 0 ; <i1> [#uses=1]84 br i1 %cmp6, label %for.body.for.end_crit_edge, label %for.inc85 86for.body.for.end_crit_edge: ; preds = %for.body87 br label %for.end88 89for.inc: ; preds = %for.body90 %indvar.next = add i32 %i.0, 1 ; <i32> [#uses=1]91 br label %for.cond92 93for.end: ; preds = %for.body.for.end_crit_edge, %for.cond.for.end_crit_edge94 %tmp9 = load i32, ptr @p ; <i32> [#uses=1]95 ret i32 %tmp996}97;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:98; CHECK: {{.*}}99