1; Ensure that IR count remarks in the legacy pass manager work. 2; What this test should check for: 3; * Positive, nonzero sizes before/after 4; * Nonzero deltas 5; * Sizes are being tracked properly across multiple remarks. E.g, if we have 6; original_count_1, final_count_1, and 7; original_count_2, final_count_2, 8; Then original_count_2 == final_count_1. 9 10; For these remarks, the "function" field in the YAML file doesn't matter. 11; Each of the testcases work by combining the output remarks with the 12; optimization record emit using -pass-remarks-output. This is done to prevent 13; test flakiness wrt instruction counts, but also ensure that the output values 14; are equivalent in both outputs. 15 16; RUN: opt < %s -inline -pass-remarks-analysis='size-info' \ 17; RUN: -pass-remarks-output=%t.yaml -S -o /dev/null 2> %t; \ 18; RUN: cat %t %t.yaml | FileCheck %s -check-prefix=CGSCC 19; CGSCC: remark: <unknown>:0:0: Function Integration/Inlining: 20; CGSCC-SAME: IR instruction count changed from 21; CGSCC-SAME: [[ORIG:[1-9][0-9]*]] to [[FINAL:[1-9][0-9]*]]; 22; CGSCC-SAME: Delta: [[DELTA:-?[1-9][0-9]*]] 23; CGSCC: --- !Analysis 24; CGSCC-NEXT: Pass: size-info 25; CGSCC-NEXT: Name: IRSizeChange 26; CGSCC-NEXT: Function: 27; CGSCC-NEXT: Args: 28; CGSCC-NEXT: - Pass: Function Integration/Inlining 29; CGSCC-NEXT: - String: ': IR instruction count changed from ' 30; CGSCC-NEXT: - IRInstrsBefore: '[[ORIG]]' 31; CGSCC-NEXT: - String: ' to ' 32; CGSCC-NEXT: - IRInstrsAfter: '[[FINAL]]' 33; CGSCC-NEXT: - String: '; Delta: ' 34; CGSCC-NEXT: - DeltaInstrCount: '[[DELTA]]' 35 36; RUN: opt < %s -instcombine -pass-remarks-analysis='size-info' \ 37; RUN:-pass-remarks-output=%t.yaml -S -o /dev/null 2> %t; \ 38; RUN: cat %t %t.yaml | FileCheck %s -check-prefix=FUNC 39; FUNC: remark: <unknown>:0:0: Combine redundant instructions: 40; FUNC-SAME: IR instruction count changed from 41; FUNC-SAME: [[SIZE1:[1-9][0-9]*]] to [[SIZE2:[1-9][0-9]*]]; 42; FUNC-SAME: Delta: [[DELTA1:-?[1-9][0-9]*]] 43; FUNC-NEXT: remark: <unknown>:0:0: Combine redundant instructions: 44; FUNC-SAME: IR instruction count changed from 45; FUNC-SAME: [[SIZE2]] to [[SIZE3:[1-9][0-9]*]]; 46; FUNC-SAME: Delta: [[DELTA2:-?[1-9][0-9]*]] 47; FUNC: --- !Analysis 48; FUNC-NEXT: Pass: size-info 49; FUNC-NEXT: Name: IRSizeChange 50; FUNC-NEXT: Function: 51; FUNC-NEXT: Args: 52; FUNC-NEXT: - Pass: Combine redundant instructions 53; FUNC-NEXT: - String: ': IR instruction count changed from ' 54; FUNC-NEXT: - IRInstrsBefore: '[[SIZE1]]' 55; FUNC-NEXT: - String: ' to ' 56; FUNC-NEXT: - IRInstrsAfter: '[[SIZE2]]' 57; FUNC-NEXT: - String: '; Delta: ' 58; FUNC-NEXT: - DeltaInstrCount: '[[DELTA1]]' 59; FUNC: --- !Analysis 60; FUNC-NEXT: Pass: size-info 61; FUNC-NEXT: Name: IRSizeChange 62; FUNC-NEXT: Function: 63; FUNC-NEXT: Args: 64; FUNC-NEXT: - Pass: Combine redundant instructions 65; FUNC-NEXT: - String: ': IR instruction count changed from ' 66; FUNC-NEXT: - IRInstrsBefore: '[[SIZE2]]' 67; FUNC-NEXT: - String: ' to ' 68; FUNC-NEXT: - IRInstrsAfter: '[[SIZE3]]' 69; FUNC-NEXT: - String: '; Delta: ' 70; FUNC-NEXT: - DeltaInstrCount: '[[DELTA2]]' 71 72; RUN: opt < %s -globaldce -pass-remarks-analysis='size-info' \ 73; RUN: -pass-remarks-output=%t.yaml -S -o /dev/null 2> %t; \ 74; RUN: cat %t %t.yaml | FileCheck %s -check-prefix=MODULE 75; MODULE: remark: 76; MODULE-SAME: Dead Global Elimination: 77; MODULE-SAME: IR instruction count changed from 78; MODULE-SAME: [[ORIG:[1-9][0-9]*]] to [[FINAL:[1-9][0-9]*]]; 79; MODULE-SAME: Delta: [[DELTA:-?[1-9][0-9]*]] 80; MODULE: --- !Analysis 81; MODULE-NEXT: Pass: size-info 82; MODULE-NEXT: Name: IRSizeChange 83; MODULE-NEXT: Function: 84; MODULE-NEXT: Args: 85; MODULE-NEXT: - Pass: Dead Global Elimination 86; MODULE-NEXT: - String: ': IR instruction count changed from ' 87; MODULE-NEXT: - IRInstrsBefore: '[[ORIG]]' 88; MODULE-NEXT: - String: ' to ' 89; MODULE-NEXT: - IRInstrsAfter: '[[FINAL]]' 90; MODULE-NEXT: - String: '; Delta: ' 91; MODULE-NEXT: - DeltaInstrCount: '[[DELTA]]' 92 93; RUN: opt < %s -dce -pass-remarks-analysis='size-info' \ 94; RUN: -pass-remarks-output=%t.yaml -S -o /dev/null 2> %t; \ 95; RUN: cat %t %t.yaml | FileCheck %s -check-prefix=BB 96; BB: remark: <unknown>:0:0: Dead Code Elimination: 97; BB-SAME: IR instruction count changed from 98; BB-SAME: [[ORIG:[1-9][0-9]*]] to [[FINAL:[1-9][0-9]*]]; 99; BB-SAME: Delta: [[DELTA:-?[1-9][0-9]*]] 100; BB: --- !Analysis 101; BB-NEXT: Pass: size-info 102; BB-NEXT: Name: IRSizeChange 103; BB-NEXT: Function: 104; BB-NEXT: Args: 105; BB-NEXT: - Pass: Dead Code Elimination 106; BB-NEXT: - String: ': IR instruction count changed from ' 107; BB-NEXT: - IRInstrsBefore: '[[ORIG]]' 108; BB-NEXT: - String: ' to ' 109; BB-NEXT: - IRInstrsAfter: '[[FINAL]]' 110; BB-NEXT: - String: '; Delta: ' 111; BB-NEXT: - DeltaInstrCount: '[[DELTA]]' 112 113; RUN: opt < %s -loop-unroll -pass-remarks-analysis='size-info' \ 114; RUN: -pass-remarks-output=%t.yaml -S -o /dev/null 2> %t; \ 115; RUN: cat %t %t.yaml | FileCheck %s -check-prefix=LOOP 116; LOOP: remark: <unknown>:0:0: Unroll loops: 117; LOOP-SAME: IR instruction count changed from 118; LOOP-SAME: [[ORIG:[1-9][0-9]*]] to [[FINAL:[1-9][0-9]*]]; 119; LOOP-SAME: Delta: [[DELTA:-?[1-9][0-9]*]] 120; LOOP: --- !Analysis 121; LOOP-NEXT: Pass: size-info 122; LOOP-NEXT: Name: IRSizeChange 123; LOOP-NEXT: Function: 124; LOOP-NEXT: Args: 125; LOOP-DAG: - Pass: Unroll loops 126; LOOP-NEXT: - String: ': IR instruction count changed from ' 127; LOOP-NEXT: - IRInstrsBefore: '[[ORIG]]' 128; LOOP-NEXT: - String: ' to ' 129; LOOP-NEXT: - IRInstrsAfter: '[[FINAL]]' 130; LOOP-NEXT: - String: '; Delta: ' 131; LOOP-NEXT: - DeltaInstrCount: '[[DELTA]]' 132declare i1 ()* @boop() 133 134define internal i1 @pluto() { 135 %F = call i1 ()* () @boop( ) 136 %c = icmp eq i1 ()* %F, @pluto 137 ret i1 %c 138} 139 140define i32 @foo(i32 %x) { 141entry: 142 %x.addr = alloca i32, align 4 143 store i32 %x, i32* %x.addr, align 4 144 %0 = load i32, i32* %x.addr, align 4 145 ret i32 %0 146} 147 148define i32 @bar(i32 %x) { 149entry: 150 %x.addr = alloca i32, align 4 151 store i32 %x, i32* %x.addr, align 4 152 %0 = load i32, i32* %x.addr, align 4 153 %call = call i32 @foo(i32 %0) 154 br label %for.body 155for.body: 156 %s.06 = phi i32 [ 0, %entry ], [ %add, %for.body ] 157 %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 158 %add = add nsw i32 %i.05, 4 159 %inc = add nsw i32 %i.05, 1 160 %exitcond = icmp eq i32 %inc, 16 161 br i1 %exitcond, label %for.end, label %for.body 162for.end: 163 ret i32 %add 164} 165