brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.9 KiB · bb9b0de Raw
278 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 62; RUN: opt -passes=gvn -S < %s | FileCheck --check-prefixes=CHECK,MDEP %s3; RUN: opt -passes='gvn<memoryssa>' -S < %s | FileCheck --check-prefixes=CHECK,MSSA %s4 5define i32 @test1(ptr %p, ptr %q) {6; MDEP-LABEL: define i32 @test1(7; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {8; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0:![0-9]+]]9; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]10; MDEP-NEXT:    ret i32 [[C]]11;12; MSSA-LABEL: define i32 @test1(13; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {14; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0:![0-9]+]]15; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]])16; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]17; MSSA-NEXT:    ret i32 [[C]]18;19  %a = call i32 @foo(ptr %p), !tbaa !020  %b = call i32 @foo(ptr %p)21  %c = add i32 %a, %b22  ret i32 %c23}24 25define i32 @test2(ptr %p, ptr %q) {26; MDEP-LABEL: define i32 @test2(27; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {28; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]29; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]30; MDEP-NEXT:    ret i32 [[C]]31;32; MSSA-LABEL: define i32 @test2(33; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {34; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]35; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]36; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]37; MSSA-NEXT:    ret i32 [[C]]38;39  %a = call i32 @foo(ptr %p), !tbaa !040  %b = call i32 @foo(ptr %p), !tbaa !041  %c = add i32 %a, %b42  ret i32 %c43}44 45define i32 @test3(ptr %p, ptr %q) {46; MDEP-LABEL: define i32 @test3(47; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {48; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[B_TBAA4:![0-9]+]]49; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]50; MDEP-NEXT:    ret i32 [[C]]51;52; MSSA-LABEL: define i32 @test3(53; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {54; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[B_TBAA4:![0-9]+]]55; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[B_TBAA4]]56; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]57; MSSA-NEXT:    ret i32 [[C]]58;59  %a = call i32 @foo(ptr %p), !tbaa !360  %b = call i32 @foo(ptr %p), !tbaa !361  %c = add i32 %a, %b62  ret i32 %c63}64 65define i32 @test4(ptr %p, ptr %q) {66; MDEP-LABEL: define i32 @test4(67; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {68; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[A_TBAA6:![0-9]+]]69; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]70; MDEP-NEXT:    ret i32 [[C]]71;72; MSSA-LABEL: define i32 @test4(73; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {74; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[A_TBAA6:![0-9]+]]75; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]76; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]77; MSSA-NEXT:    ret i32 [[C]]78;79  %a = call i32 @foo(ptr %p), !tbaa !180  %b = call i32 @foo(ptr %p), !tbaa !081  %c = add i32 %a, %b82  ret i32 %c83}84 85define i32 @test5(ptr %p, ptr %q) {86; MDEP-LABEL: define i32 @test5(87; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {88; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]89; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]90; MDEP-NEXT:    ret i32 [[C]]91;92; MSSA-LABEL: define i32 @test5(93; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {94; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]95; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[A_TBAA6]]96; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]97; MSSA-NEXT:    ret i32 [[C]]98;99  %a = call i32 @foo(ptr %p), !tbaa !0100  %b = call i32 @foo(ptr %p), !tbaa !1101  %c = add i32 %a, %b102  ret i32 %c103}104 105define i32 @test6(ptr %p, ptr %q) {106; MDEP-LABEL: define i32 @test6(107; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {108; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]109; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]110; MDEP-NEXT:    ret i32 [[C]]111;112; MSSA-LABEL: define i32 @test6(113; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {114; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[C_TBAA0]]115; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[B_TBAA4]]116; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]117; MSSA-NEXT:    ret i32 [[C]]118;119  %a = call i32 @foo(ptr %p), !tbaa !0120  %b = call i32 @foo(ptr %p), !tbaa !3121  %c = add i32 %a, %b122  ret i32 %c123}124 125define i32 @test7(ptr %p, ptr %q) {126; MDEP-LABEL: define i32 @test7(127; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {128; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[SCALAR_TYPE_TBAA7:![0-9]+]]129; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]130; MDEP-NEXT:    ret i32 [[C]]131;132; MSSA-LABEL: define i32 @test7(133; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {134; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[SCALAR_TYPE_TBAA7:![0-9]+]]135; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[B_TBAA4]]136; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]137; MSSA-NEXT:    ret i32 [[C]]138;139  %a = call i32 @foo(ptr %p), !tbaa !4140  %b = call i32 @foo(ptr %p), !tbaa !3141  %c = add i32 %a, %b142  ret i32 %c143}144 145define i32 @test8(ptr %p, ptr %q) {146; MDEP-LABEL: define i32 @test8(147; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {148; MDEP-NEXT:    store i32 15, ptr [[P]], align 4149; MDEP-NEXT:    ret i32 0150;151; MSSA-LABEL: define i32 @test8(152; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {153; MSSA-NEXT:    [[A:%.*]] = load i32, ptr [[Q]], align 4, !tbaa [[NODE_TBAA10:![0-9]+]]154; MSSA-NEXT:    store i32 15, ptr [[P]], align 4155; MSSA-NEXT:    [[B:%.*]] = load i32, ptr [[Q]], align 4, !tbaa [[NODE_TBAA10]]156; MSSA-NEXT:    [[C:%.*]] = sub i32 [[A]], [[B]]157; MSSA-NEXT:    ret i32 [[C]]158;159; Since we know the location is invariant, we can forward the160; load across the potentially aliasing store.161 162  %a = load i32, ptr %q, !tbaa !10163  store i32 15, ptr %p164  %b = load i32, ptr %q, !tbaa !10165  %c = sub i32 %a, %b166  ret i32 %c167}168 169define i32 @test9(ptr %p, ptr %q) {170; MDEP-LABEL: define i32 @test9(171; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {172; MDEP-NEXT:    call void @clobber()173; MDEP-NEXT:    ret i32 0174;175; MSSA-LABEL: define i32 @test9(176; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {177; MSSA-NEXT:    [[A:%.*]] = load i32, ptr [[Q]], align 4, !tbaa [[NODE_TBAA10]]178; MSSA-NEXT:    call void @clobber()179; MSSA-NEXT:    [[B:%.*]] = load i32, ptr [[Q]], align 4, !tbaa [[NODE_TBAA10]]180; MSSA-NEXT:    [[C:%.*]] = sub i32 [[A]], [[B]]181; MSSA-NEXT:    ret i32 [[C]]182;183; Since we know the location is invariant, we can forward the184; load across the potentially aliasing store (within the call).185 186  %a = load i32, ptr %q, !tbaa !10187  call void @clobber()188  %b = load i32, ptr %q, !tbaa !10189  %c = sub i32 %a, %b190  ret i32 %c191}192 193define i32 @test10(ptr %p, ptr %q) {194; If one access encloses the other, then the merged access is the enclosed one195; and not just the common final access type.196; MDEP-LABEL: define i32 @test10(197; MDEP-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {198; MDEP-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[INT_TBAA10:![0-9]+]]199; MDEP-NEXT:    [[C:%.*]] = add i32 [[A]], [[A]]200; MDEP-NEXT:    ret i32 [[C]]201;202; MSSA-LABEL: define i32 @test10(203; MSSA-SAME: ptr [[P:%.*]], ptr [[Q:%.*]]) {204; MSSA-NEXT:    [[A:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[INT_TBAA13:![0-9]+]]205; MSSA-NEXT:    [[B:%.*]] = call i32 @foo(ptr [[P]]), !tbaa [[INT_TBAA17:![0-9]+]]206; MSSA-NEXT:    [[C:%.*]] = add i32 [[A]], [[B]]207; MSSA-NEXT:    ret i32 [[C]]208;209  %a = call i32 @foo(ptr %p), !tbaa !15  ; TAG_X_i210  %b = call i32 @foo(ptr %p), !tbaa !19  ; TAG_Y_x_i211  %c = add i32 %a, %b212  ret i32 %c213}214 215declare void @clobber()216declare i32 @foo(ptr) readonly217 218!0 = !{!5, !5, i64 0}219!1 = !{!6, !6, i64 0}220!2 = !{!"tbaa root"}221!3 = !{!7, !7, i64 0}222!4 = !{!11, !11, i64 0}223!5 = !{!"C", !6}224!6 = !{!"A", !2}225!7 = !{!"B", !6}226!8 = !{!"another root"}227!11 = !{!"scalar type", !8}228 229!15 = !{!16, !17, i64 0}            ; TAG_X_i230!16 = !{!"struct X", !17, i64 0}    ; struct X { int i; };231!17 = !{!"int", !18, i64 0}232!18 = !{!"char", !2, i64 0}233 234!19 = !{!20, !17, i64 0}            ; TAG_Y_x_i235!20 = !{!"struct Y", !16, i64 0}    ; struct Y { struct X x; };236 237; A TBAA structure who's only point is to have a constant location.238!9 = !{!"yet another root"}239!10 = !{!"node", !9, i64 1}240;.241; MDEP: [[C_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}242; MDEP: [[META1]] = !{!"C", [[META2:![0-9]+]]}243; MDEP: [[META2]] = !{!"A", [[META3:![0-9]+]]}244; MDEP: [[META3]] = !{!"tbaa root"}245; MDEP: [[B_TBAA4]] = !{[[META5:![0-9]+]], [[META5]], i64 0}246; MDEP: [[META5]] = !{!"B", [[META2]]}247; MDEP: [[A_TBAA6]] = !{[[META2]], [[META2]], i64 0}248; MDEP: [[SCALAR_TYPE_TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}249; MDEP: [[META8]] = !{!"scalar type", [[META9:![0-9]+]]}250; MDEP: [[META9]] = !{!"another root"}251; MDEP: [[INT_TBAA10]] = !{[[META11:![0-9]+]], [[META12:![0-9]+]], i64 0}252; MDEP: [[META11]] = !{!"struct X", [[META12]], i64 0}253; MDEP: [[META12]] = !{!"int", [[META13:![0-9]+]], i64 0}254; MDEP: [[META13]] = !{!"char", [[META3]], i64 0}255;.256; MSSA: [[C_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}257; MSSA: [[META1]] = !{!"C", [[META2:![0-9]+]]}258; MSSA: [[META2]] = !{!"A", [[META3:![0-9]+]]}259; MSSA: [[META3]] = !{!"tbaa root"}260; MSSA: [[B_TBAA4]] = !{[[META5:![0-9]+]], [[META5]], i64 0}261; MSSA: [[META5]] = !{!"B", [[META2]]}262; MSSA: [[A_TBAA6]] = !{[[META2]], [[META2]], i64 0}263; MSSA: [[SCALAR_TYPE_TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}264; MSSA: [[META8]] = !{!"scalar type", [[META9:![0-9]+]]}265; MSSA: [[META9]] = !{!"another root"}266; MSSA: [[NODE_TBAA10]] = !{[[META11:![0-9]+]], [[META11]], i64 0, i64 1}267; MSSA: [[META11]] = !{!"node", [[META12:![0-9]+]]}268; MSSA: [[META12]] = !{!"yet another root"}269; MSSA: [[INT_TBAA13]] = !{[[META14:![0-9]+]], [[META15:![0-9]+]], i64 0}270; MSSA: [[META14]] = !{!"struct X", [[META15]], i64 0}271; MSSA: [[META15]] = !{!"int", [[META16:![0-9]+]], i64 0}272; MSSA: [[META16]] = !{!"char", [[META3]], i64 0}273; MSSA: [[INT_TBAA17]] = !{[[META18:![0-9]+]], [[META15]], i64 0}274; MSSA: [[META18]] = !{!"struct Y", [[META14]], i64 0}275;.276;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:277; CHECK: {{.*}}278