11; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2- ; RUN: opt -passes='require<aa>, flatten-cfg' -S < %s | FileCheck %s
2+ ; RUN: opt -passes=flatten-cfg -S < %s | FileCheck %s
33
44
55; This test checks whether the pass completes without a crash.
@@ -310,6 +310,9 @@ exit:
310310 ret i1 %cmp.y
311311}
312312
313+ declare void @foo ()
314+ declare void @bar () #1
315+
313316; Test that two if-regions are not merged when there's potential aliasing
314317; between a store in the first if-region and a load in the second if-region's header
315318define i32 @test_alias (i32 %a , i32 %b , ptr %p1 , ptr %p2 ) {
@@ -354,6 +357,52 @@ if.end2:
354357 ret i32 0
355358}
356359
360+ ; Test that two if-regions are not merged when there's potential aliasing
361+ ; between a fuction call in the first if-region and a load in the second if-region's header
362+ define i32 @test_alias_2 (i32 %a , i32 %b ) {
363+ ; CHECK-LABEL: define i32 @test_alias_2
364+ ; CHECK-SAME: (i32 [[A:%.*]], i32 [[B:%.*]]) {
365+ ; CHECK-NEXT: entry:
366+ ; CHECK-NEXT: [[P:%.*]] = alloca i32, align 4
367+ ; CHECK-NEXT: store i32 42, ptr [[P]], align 4
368+ ; CHECK-NEXT: [[COND1:%.*]] = icmp eq i32 [[A]], 0
369+ ; CHECK-NEXT: br i1 [[COND1]], label [[IF_THEN1:%.*]], label [[IF_END1:%.*]]
370+ ; CHECK: if.then1:
371+ ; CHECK-NEXT: call void @foo()
372+ ; CHECK-NEXT: br label [[IF_END1]]
373+ ; CHECK: if.end1:
374+ ; CHECK-NEXT: [[VAL:%.*]] = load i32, ptr @g, align 4
375+ ; CHECK-NEXT: [[COND2:%.*]] = icmp eq i32 [[B]], 0
376+ ; CHECK-NEXT: br i1 [[COND2]], label [[IF_THEN2:%.*]], label [[IF_END2:%.*]]
377+ ; CHECK: if.then2:
378+ ; CHECK-NEXT: call void @foo()
379+ ; CHECK-NEXT: br label [[IF_END2]]
380+ ; CHECK: if.end2:
381+ ; CHECK-NEXT: ret i32 0
382+ ;
383+ entry:
384+ %p = alloca i32
385+ store i32 42 , ptr %p
386+ %cond1 = icmp eq i32 %a , 0
387+ br i1 %cond1 , label %if.then1 , label %if.end1
388+
389+ if.then1:
390+ call void @foo ()
391+ br label %if.end1
392+
393+ if.end1:
394+ %val = load i32 , ptr @g
395+ %cond2 = icmp eq i32 %b , 0
396+ br i1 %cond2 , label %if.then2 , label %if.end2
397+
398+ if.then2:
399+ call void @foo ()
400+ br label %if.end2
401+
402+ if.end2:
403+ ret i32 0
404+ }
405+
357406; Test that two if-regions are merged when there's no potential aliasing
358407; between a store in the first if-region and a load in the second if-region's header
359408define i32 @test_no_alias (i32 %a , i32 %b ) {
@@ -369,18 +418,20 @@ define i32 @test_no_alias(i32 %a, i32 %b) {
369418; CHECK-NEXT: br i1 [[TMP0]], label [[IF_THEN2:%.*]], label [[IF_END2:%.*]]
370419; CHECK: if.then2:
371420; CHECK-NEXT: store i32 100, ptr [[P]], align 4
421+ ; CHECK-NEXT: call void @bar()
372422; CHECK-NEXT: br label [[IF_END2]]
373423; CHECK: if.end2:
374424; CHECK-NEXT: ret i32 0
375425;
376- entry:
426+ entry:
377427 %p = alloca i32
378428 store i32 42 , ptr %p
379429 %cond1 = icmp eq i32 %a , 0
380430 br i1 %cond1 , label %if.then1 , label %if.end1
381431
382432if.then1:
383433 store i32 100 , ptr %p ; No alias with the load below
434+ call void @bar () ; No alias with the load below since it's a pure function
384435 br label %if.end1
385436
386437if.end1:
@@ -390,8 +441,11 @@ if.end1:
390441
391442if.then2:
392443 store i32 100 , ptr %p
444+ call void @bar ()
393445 br label %if.end2
394446
395447if.end2:
396448 ret i32 0
397- }
449+ }
450+
451+ attributes #1 = { readnone willreturn nounwind }
0 commit comments