1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py 2; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f,+short-forward-branch-opt -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=SFB64 3; RUN: opt < %s -mtriple=riscv64 -mattr=+v,+f -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=RV64 4 5define i32 @icmp-iselect(i64 %ca, i64 %cb, i32 %a, i32 %b) { 6; SFB64-LABEL: 'icmp-iselect' 7; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 %ca, %cb 8; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b 9; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1 10; 11; RV64-LABEL: 'icmp-iselect' 12; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb 13; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b 14; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1 15; 16 %cmp1 = icmp slt i64 %ca, %cb 17 %select1 = select i1 %cmp1, i32 %a, i32 %b 18 ret i32 %select1 19} 20 21define i32 @icmp-iselects(i64 %ca, i64 %cb, i32 %a, i32 %b, i32 %c) { 22; SFB64-LABEL: 'icmp-iselects' 23; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 %ca, %cb 24; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b 25; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, i32 %a, i32 %c 26; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %select2 27; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret 28; 29; RV64-LABEL: 'icmp-iselects' 30; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb 31; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b 32; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, i32 %a, i32 %c 33; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %select2 34; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret 35; 36 %cmp1 = icmp slt i64 %ca, %cb 37 %select1 = select i1 %cmp1, i32 %a, i32 %b 38 %select2 = select i1 %cmp1, i32 %a, i32 %c 39 %ret = add i32 %select1, %select2 40 ret i32 %ret 41} 42 43define i32 @icmp-ifselects(i64 %ca, i64 %cb, i32 %a, i32 %b, float %c, float %d) { 44; SFB64-LABEL: 'icmp-ifselects' 45; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb 46; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b 47; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, float %c, float %d 48; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %selectint = fptosi float %select2 to i32 49; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %selectint 50; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret 51; 52; RV64-LABEL: 'icmp-ifselects' 53; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb 54; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 %b 55; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select2 = select i1 %cmp1, float %c, float %d 56; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %selectint = fptosi float %select2 to i32 57; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %ret = add i32 %select1, %selectint 58; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %ret 59; 60 %cmp1 = icmp slt i64 %ca, %cb 61 %select1 = select i1 %cmp1, i32 %a, i32 %b 62 %select2 = select i1 %cmp1, float %c, float %d 63 %selectint = fptosi float %select2 to i32 64 %ret = add i32 %select1, %selectint 65 ret i32 %ret 66} 67 68define i32 @constant-icmp-iselect(i64 %ca, i64 %cb, i32 %a) { 69; SFB64-LABEL: 'constant-icmp-iselect' 70; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb 71; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 7 72; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1 73; 74; RV64-LABEL: 'constant-icmp-iselect' 75; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 %ca, %cb 76; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 %a, i32 7 77; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1 78; 79 %cmp1 = icmp slt i64 %ca, %cb 80 %select1 = select i1 %cmp1, i32 %a, i32 7 81 ret i32 %select1 82} 83 84define i32 @fcmp-iselect(float %ca, float %cb, i32 %a, i32 %b) { 85; SFB64-LABEL: 'fcmp-iselect' 86; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 87; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 %a, i32 %b 88; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1 89; 90; RV64-LABEL: 'fcmp-iselect' 91; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 92; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %fcmp1, i32 %a, i32 %b 93; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 %select1 94; 95 %fcmp1 = fcmp ogt float %ca, %cb 96 %select1 = select i1 %fcmp1, i32 %a, i32 %b 97 ret i32 %select1 98} 99 100define float @fcmp-fselect(float %ca, float %cb, float %a, float %b) { 101; SFB64-LABEL: 'fcmp-fselect' 102; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 103; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %fcmp1, float %a, float %b 104; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1 105; 106; RV64-LABEL: 'fcmp-fselect' 107; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 108; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %fcmp1, float %a, float %b 109; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1 110; 111 %fcmp1 = fcmp ogt float %ca, %cb 112 %fselect1 = select i1 %fcmp1, float %a, float %b 113 ret float %fselect1 114} 115 116define float @icmp-fselect(i64 %ca, i64 %cb, float %a, float %b) { 117; SFB64-LABEL: 'icmp-fselect' 118; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i64 %ca, %cb 119; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %icmp1, float %a, float %b 120; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1 121; 122; RV64-LABEL: 'icmp-fselect' 123; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i64 %ca, %cb 124; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fselect1 = select i1 %icmp1, float %a, float %b 125; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret float %fselect1 126; 127 %icmp1 = icmp slt i64 %ca, %cb 128 %fselect1 = select i1 %icmp1, float %a, float %b 129 ret float %fselect1 130} 131 132define <2 x i32> @vector-icmp-vector-iselect(<2 x i32> %ca, <2 x i32> %cb, <2 x i32> %a, <2 x i32> %b) { 133; SFB64-LABEL: 'vector-icmp-vector-iselect' 134; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp = icmp slt <2 x i32> %ca, %cb 135; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %icmp, <2 x i32> %a, <2 x i32> %b 136; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 137; 138; RV64-LABEL: 'vector-icmp-vector-iselect' 139; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp = icmp slt <2 x i32> %ca, %cb 140; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %icmp, <2 x i32> %a, <2 x i32> %b 141; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 142; 143 %icmp = icmp slt <2 x i32> %ca, %cb 144 %select1 = select <2 x i1> %icmp, <2 x i32> %a, <2 x i32> %b 145 ret <2 x i32> %select1 146} 147 148define <2 x i32> @vector-fcmp-vector-iselect(<2 x float> %ca, <2 x float> %cb, <2 x i32> %a, <2 x i32> %b) { 149; SFB64-LABEL: 'vector-fcmp-vector-iselect' 150; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb 151; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x i32> %a, <2 x i32> %b 152; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 153; 154; RV64-LABEL: 'vector-fcmp-vector-iselect' 155; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb 156; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x i32> %a, <2 x i32> %b 157; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 158; 159 %fcmp1 = fcmp ogt <2 x float> %ca, %cb 160 %select1 = select <2 x i1> %fcmp1, <2 x i32> %a, <2 x i32> %b 161 ret <2 x i32> %select1 162} 163 164define <2 x float> @vector-fcmp-vector-fselect(<2 x float> %ca, <2 x float> %cb, <2 x float> %a, <2 x float> %b) { 165; SFB64-LABEL: 'vector-fcmp-vector-fselect' 166; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb 167; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x float> %a, <2 x float> %b 168; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 169; 170; RV64-LABEL: 'vector-fcmp-vector-fselect' 171; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt <2 x float> %ca, %cb 172; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %fcmp1, <2 x float> %a, <2 x float> %b 173; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 174; 175 %fcmp1 = fcmp ogt <2 x float> %ca, %cb 176 %select1 = select <2 x i1> %fcmp1, <2 x float> %a, <2 x float> %b 177 ret <2 x float> %select1 178} 179 180define <2 x float> @vector-icmp-vector-fselect(<2 x i32> %ca, <2 x i32> %cb, <2 x float> %a, <2 x float> %b) { 181; SFB64-LABEL: 'vector-icmp-vector-fselect' 182; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt <2 x i32> %ca, %cb 183; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %icmp1, <2 x float> %a, <2 x float> %b 184; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 185; 186; RV64-LABEL: 'vector-icmp-vector-fselect' 187; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt <2 x i32> %ca, %cb 188; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select <2 x i1> %icmp1, <2 x float> %a, <2 x float> %b 189; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 190; 191 %icmp1 = icmp slt <2 x i32> %ca, %cb 192 %select1 = select <2 x i1> %icmp1, <2 x float> %a, <2 x float> %b 193 ret <2 x float> %select1 194} 195 196define <2 x float> @icmp-vector-fselect(i1 %ca, i1 %cb, <2 x float> %a, <2 x float> %b) { 197; SFB64-LABEL: 'icmp-vector-fselect' 198; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb 199; SFB64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %icmp1, <2 x float> %a, <2 x float> %b 200; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 201; 202; RV64-LABEL: 'icmp-vector-fselect' 203; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb 204; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %icmp1, <2 x float> %a, <2 x float> %b 205; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 206; 207 %icmp1 = icmp slt i1 %ca, %cb 208 %select1 = select i1 %icmp1, <2 x float> %a, <2 x float> %b 209 ret <2 x float> %select1 210} 211 212define <2 x i32> @icmp-vector-iselect(i1 %ca, i1 %cb, <2 x i32> %a, <2 x i32> %b) { 213; SFB64-LABEL: 'icmp-vector-iselect' 214; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb 215; SFB64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %icmp1, <2 x i32> %a, <2 x i32> %b 216; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 217; 218; RV64-LABEL: 'icmp-vector-iselect' 219; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %icmp1 = icmp slt i1 %ca, %cb 220; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %icmp1, <2 x i32> %a, <2 x i32> %b 221; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 222; 223 %icmp1 = icmp slt i1 %ca, %cb 224 %select1 = select i1 %icmp1, <2 x i32> %a, <2 x i32> %b 225 ret <2 x i32> %select1 226} 227 228define <2 x float> @fcmp-vector-fselect(float %ca, float %cb, <2 x float> %a, <2 x float> %b) { 229; SFB64-LABEL: 'fcmp-vector-fselect' 230; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 231; SFB64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %fcmp1, <2 x float> %a, <2 x float> %b 232; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 233; 234; RV64-LABEL: 'fcmp-vector-fselect' 235; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 236; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %fcmp1, <2 x float> %a, <2 x float> %b 237; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x float> %select1 238; 239 %fcmp1 = fcmp ogt float %ca, %cb 240 %select1 = select i1 %fcmp1, <2 x float> %a, <2 x float> %b 241 ret <2 x float> %select1 242} 243 244define <2 x i32> @fcmp-vector-iselect(float %ca, float %cb, <2 x i32> %a, <2 x i32> %b) { 245; SFB64-LABEL: 'fcmp-vector-iselect' 246; SFB64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 247; SFB64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %fcmp1, <2 x i32> %a, <2 x i32> %b 248; SFB64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 249; 250; RV64-LABEL: 'fcmp-vector-iselect' 251; RV64-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %fcmp1 = fcmp ogt float %ca, %cb 252; RV64-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %select1 = select i1 %fcmp1, <2 x i32> %a, <2 x i32> %b 253; RV64-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <2 x i32> %select1 254; 255 %fcmp1 = fcmp ogt float %ca, %cb 256 %select1 = select i1 %fcmp1, <2 x i32> %a, <2 x i32> %b 257 ret <2 x i32> %select1 258} 259