1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4; https://bugs.llvm.org/show_bug.cgi?id=37603 5; https://reviews.llvm.org/D46760#1123713 6 7; Pattern: 8; x >> y << y 9; Should be transformed into: 10; x & (-1 << y) 11 12; ============================================================================ ; 13; Basic positive tests 14; ============================================================================ ; 15 16define i8 @positive_samevar(i8 %x, i8 %y) { 17; CHECK-LABEL: @positive_samevar( 18; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]] 19; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]] 20; CHECK-NEXT: ret i8 [[RET]] 21; 22 %tmp0 = ashr i8 %x, %y 23 %ret = shl i8 %tmp0, %y 24 ret i8 %ret 25} 26 27define i8 @positive_sameconst(i8 %x) { 28; CHECK-LABEL: @positive_sameconst( 29; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -8 30; CHECK-NEXT: ret i8 [[TMP1]] 31; 32 %tmp0 = ashr i8 %x, 3 33 %ret = shl i8 %tmp0, 3 34 ret i8 %ret 35} 36 37define i8 @positive_biggerashr(i8 %x) { 38; CHECK-LABEL: @positive_biggerashr( 39; CHECK-NEXT: [[TMP1:%.*]] = ashr i8 [[X:%.*]], 3 40; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -8 41; CHECK-NEXT: ret i8 [[RET]] 42; 43 %tmp0 = ashr i8 %x, 6 44 %ret = shl i8 %tmp0, 3 45 ret i8 %ret 46} 47 48define i8 @positive_biggershl(i8 %x) { 49; CHECK-LABEL: @positive_biggershl( 50; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[X:%.*]], 3 51; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -64 52; CHECK-NEXT: ret i8 [[RET]] 53; 54 %tmp0 = ashr i8 %x, 3 55 %ret = shl i8 %tmp0, 6 56 ret i8 %ret 57} 58 59; ============================================================================ ; 60; shl nuw 61; ============================================================================ ; 62 63define i8 @positive_samevar_shlnuw(i8 %x, i8 %y) { 64; CHECK-LABEL: @positive_samevar_shlnuw( 65; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]] 66; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]] 67; CHECK-NEXT: ret i8 [[RET]] 68; 69 %tmp0 = ashr i8 %x, %y 70 %ret = shl nuw i8 %tmp0, %y 71 ret i8 %ret 72} 73 74define i8 @positive_sameconst_shlnuw(i8 %x) { 75; CHECK-LABEL: @positive_sameconst_shlnuw( 76; CHECK-NEXT: [[RET:%.*]] = and i8 [[X:%.*]], -8 77; CHECK-NEXT: ret i8 [[RET]] 78; 79 %tmp0 = ashr i8 %x, 3 80 %ret = shl nuw i8 %tmp0, 3 81 ret i8 %ret 82} 83 84define i8 @positive_biggerashr_shlnuw(i8 %x) { 85; CHECK-LABEL: @positive_biggerashr_shlnuw( 86; CHECK-NEXT: [[TMP1:%.*]] = ashr i8 [[X:%.*]], 3 87; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -8 88; CHECK-NEXT: ret i8 [[RET]] 89; 90 %tmp0 = ashr i8 %x, 6 91 %ret = shl nuw i8 %tmp0, 3 92 ret i8 %ret 93} 94 95define i8 @positive_biggershl_shlnuw(i8 %x) { 96; CHECK-LABEL: @positive_biggershl_shlnuw( 97; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i8 [[X:%.*]], 3 98; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -64 99; CHECK-NEXT: ret i8 [[RET]] 100; 101 %tmp0 = ashr i8 %x, 3 102 %ret = shl nuw i8 %tmp0, 6 103 ret i8 %ret 104} 105 106; ============================================================================ ; 107; shl nsw 108; ============================================================================ ; 109 110define i8 @positive_samevar_shlnsw(i8 %x, i8 %y) { 111; CHECK-LABEL: @positive_samevar_shlnsw( 112; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]] 113; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]] 114; CHECK-NEXT: ret i8 [[RET]] 115; 116 %tmp0 = ashr i8 %x, %y 117 %ret = shl nsw i8 %tmp0, %y 118 ret i8 %ret 119} 120 121define i8 @positive_sameconst_shlnsw(i8 %x) { 122; CHECK-LABEL: @positive_sameconst_shlnsw( 123; CHECK-NEXT: [[RET:%.*]] = and i8 [[X:%.*]], -8 124; CHECK-NEXT: ret i8 [[RET]] 125; 126 %tmp0 = ashr i8 %x, 3 127 %ret = shl nsw i8 %tmp0, 3 128 ret i8 %ret 129} 130 131define i8 @positive_biggerashr_shlnsw(i8 %x) { 132; CHECK-LABEL: @positive_biggerashr_shlnsw( 133; CHECK-NEXT: [[TMP1:%.*]] = ashr i8 [[X:%.*]], 3 134; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -8 135; CHECK-NEXT: ret i8 [[RET]] 136; 137 %tmp0 = ashr i8 %x, 6 138 %ret = shl nsw i8 %tmp0, 3 139 ret i8 %ret 140} 141 142define i8 @positive_biggershl_shlnsw(i8 %x) { 143; CHECK-LABEL: @positive_biggershl_shlnsw( 144; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i8 [[X:%.*]], 3 145; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -64 146; CHECK-NEXT: ret i8 [[RET]] 147; 148 %tmp0 = ashr i8 %x, 3 149 %ret = shl nsw i8 %tmp0, 6 150 ret i8 %ret 151} 152 153; ============================================================================ ; 154; shl nuw nsw 155; ============================================================================ ; 156 157define i8 @positive_samevar_shlnuwnsw(i8 %x, i8 %y) { 158; CHECK-LABEL: @positive_samevar_shlnuwnsw( 159; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -1, [[Y:%.*]] 160; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], [[X:%.*]] 161; CHECK-NEXT: ret i8 [[RET]] 162; 163 %tmp0 = ashr i8 %x, %y 164 %ret = shl nuw nsw i8 %tmp0, %y 165 ret i8 %ret 166} 167 168define i8 @positive_sameconst_shlnuwnsw(i8 %x) { 169; CHECK-LABEL: @positive_sameconst_shlnuwnsw( 170; CHECK-NEXT: [[RET:%.*]] = and i8 [[X:%.*]], -8 171; CHECK-NEXT: ret i8 [[RET]] 172; 173 %tmp0 = ashr i8 %x, 3 174 %ret = shl nuw nsw i8 %tmp0, 3 175 ret i8 %ret 176} 177 178define i8 @positive_biggerashr_shlnuwnsw(i8 %x) { 179; CHECK-LABEL: @positive_biggerashr_shlnuwnsw( 180; CHECK-NEXT: [[TMP1:%.*]] = ashr i8 [[X:%.*]], 3 181; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -8 182; CHECK-NEXT: ret i8 [[RET]] 183; 184 %tmp0 = ashr i8 %x, 6 185 %ret = shl nuw nsw i8 %tmp0, 3 186 ret i8 %ret 187} 188 189define i8 @positive_biggershl_shlnuwnsw(i8 %x) { 190; CHECK-LABEL: @positive_biggershl_shlnuwnsw( 191; CHECK-NEXT: [[TMP1:%.*]] = shl nuw nsw i8 [[X:%.*]], 3 192; CHECK-NEXT: [[RET:%.*]] = and i8 [[TMP1]], -64 193; CHECK-NEXT: ret i8 [[RET]] 194; 195 %tmp0 = ashr i8 %x, 3 196 %ret = shl nuw nsw i8 %tmp0, 6 197 ret i8 %ret 198} 199 200; ============================================================================ ; 201; ashr exact 202; ============================================================================ ; 203 204define i8 @positive_samevar_ashrexact(i8 %x, i8 %y) { 205; CHECK-LABEL: @positive_samevar_ashrexact( 206; CHECK-NEXT: ret i8 [[X:%.*]] 207; 208 %tmp0 = ashr exact i8 %x, %y 209 %ret = shl i8 %tmp0, %y 210 ret i8 %ret 211} 212 213define i8 @positive_sameconst_ashrexact(i8 %x) { 214; CHECK-LABEL: @positive_sameconst_ashrexact( 215; CHECK-NEXT: ret i8 [[X:%.*]] 216; 217 %tmp0 = ashr exact i8 %x, 3 218 %ret = shl i8 %tmp0, 3 219 ret i8 %ret 220} 221 222define i8 @positive_biggerashr_ashrexact(i8 %x) { 223; CHECK-LABEL: @positive_biggerashr_ashrexact( 224; CHECK-NEXT: [[RET:%.*]] = ashr exact i8 [[X:%.*]], 3 225; CHECK-NEXT: ret i8 [[RET]] 226; 227 %tmp0 = ashr exact i8 %x, 6 228 %ret = shl i8 %tmp0, 3 229 ret i8 %ret 230} 231 232define i8 @positive_biggershl_ashrexact(i8 %x) { 233; CHECK-LABEL: @positive_biggershl_ashrexact( 234; CHECK-NEXT: [[RET:%.*]] = shl i8 [[X:%.*]], 3 235; CHECK-NEXT: ret i8 [[RET]] 236; 237 %tmp0 = ashr exact i8 %x, 3 238 %ret = shl i8 %tmp0, 6 239 ret i8 %ret 240} 241 242; ============================================================================ ; 243; ashr exact, shl nsw 244; ============================================================================ ; 245 246define i8 @positive_samevar_shlnsw_ashrexact(i8 %x, i8 %y) { 247; CHECK-LABEL: @positive_samevar_shlnsw_ashrexact( 248; CHECK-NEXT: ret i8 [[X:%.*]] 249; 250 %tmp0 = ashr exact i8 %x, %y 251 %ret = shl nsw i8 %tmp0, %y 252 ret i8 %ret 253} 254 255define i8 @positive_sameconst_shlnsw_ashrexact(i8 %x) { 256; CHECK-LABEL: @positive_sameconst_shlnsw_ashrexact( 257; CHECK-NEXT: ret i8 [[X:%.*]] 258; 259 %tmp0 = ashr exact i8 %x, 3 260 %ret = shl nsw i8 %tmp0, 3 261 ret i8 %ret 262} 263 264define i8 @positive_biggerashr_shlnsw_ashrexact(i8 %x) { 265; CHECK-LABEL: @positive_biggerashr_shlnsw_ashrexact( 266; CHECK-NEXT: [[RET:%.*]] = ashr exact i8 [[X:%.*]], 3 267; CHECK-NEXT: ret i8 [[RET]] 268; 269 %tmp0 = ashr exact i8 %x, 6 270 %ret = shl nsw i8 %tmp0, 3 271 ret i8 %ret 272} 273 274define i8 @positive_biggershl_shlnsw_ashrexact(i8 %x) { 275; CHECK-LABEL: @positive_biggershl_shlnsw_ashrexact( 276; CHECK-NEXT: [[RET:%.*]] = shl nsw i8 [[X:%.*]], 3 277; CHECK-NEXT: ret i8 [[RET]] 278; 279 %tmp0 = ashr exact i8 %x, 3 280 %ret = shl nsw i8 %tmp0, 6 281 ret i8 %ret 282} 283 284; ============================================================================ ; 285; ashr exact, shl nuw 286; ============================================================================ ; 287 288define i8 @positive_samevar_shlnuw_ashrexact(i8 %x, i8 %y) { 289; CHECK-LABEL: @positive_samevar_shlnuw_ashrexact( 290; CHECK-NEXT: ret i8 [[X:%.*]] 291; 292 %tmp0 = ashr exact i8 %x, %y 293 %ret = shl nuw i8 %tmp0, %y 294 ret i8 %ret 295} 296 297define i8 @positive_sameconst_shlnuw_ashrexact(i8 %x) { 298; CHECK-LABEL: @positive_sameconst_shlnuw_ashrexact( 299; CHECK-NEXT: ret i8 [[X:%.*]] 300; 301 %tmp0 = ashr exact i8 %x, 3 302 %ret = shl nuw i8 %tmp0, 3 303 ret i8 %ret 304} 305 306define i8 @positive_biggerashr_shlnuw_ashrexact(i8 %x) { 307; CHECK-LABEL: @positive_biggerashr_shlnuw_ashrexact( 308; CHECK-NEXT: [[RET:%.*]] = ashr exact i8 [[X:%.*]], 3 309; CHECK-NEXT: ret i8 [[RET]] 310; 311 %tmp0 = ashr exact i8 %x, 6 312 %ret = shl nuw i8 %tmp0, 3 313 ret i8 %ret 314} 315 316define i8 @positive_biggershl_shlnuw_ashrexact(i8 %x) { 317; CHECK-LABEL: @positive_biggershl_shlnuw_ashrexact( 318; CHECK-NEXT: [[RET:%.*]] = shl nuw i8 [[X:%.*]], 3 319; CHECK-NEXT: ret i8 [[RET]] 320; 321 %tmp0 = ashr exact i8 %x, 3 322 %ret = shl nuw i8 %tmp0, 6 323 ret i8 %ret 324} 325 326; ============================================================================ ; 327; ashr exact, shl nuw nsw 328; ============================================================================ ; 329 330define i8 @positive_samevar_shlnuwnsw_ashrexact(i8 %x, i8 %y) { 331; CHECK-LABEL: @positive_samevar_shlnuwnsw_ashrexact( 332; CHECK-NEXT: ret i8 [[X:%.*]] 333; 334 %tmp0 = ashr exact i8 %x, %y 335 %ret = shl nuw nsw i8 %tmp0, %y 336 ret i8 %ret 337} 338 339define i8 @positive_sameconst_shlnuwnsw_ashrexact(i8 %x) { 340; CHECK-LABEL: @positive_sameconst_shlnuwnsw_ashrexact( 341; CHECK-NEXT: ret i8 [[X:%.*]] 342; 343 %tmp0 = ashr exact i8 %x, 3 344 %ret = shl nuw nsw i8 %tmp0, 3 345 ret i8 %ret 346} 347 348define i8 @positive_biggerashr_shlnuwnsw_ashrexact(i8 %x) { 349; CHECK-LABEL: @positive_biggerashr_shlnuwnsw_ashrexact( 350; CHECK-NEXT: [[RET:%.*]] = ashr exact i8 [[X:%.*]], 3 351; CHECK-NEXT: ret i8 [[RET]] 352; 353 %tmp0 = ashr exact i8 %x, 6 354 %ret = shl nuw nsw i8 %tmp0, 3 355 ret i8 %ret 356} 357 358define i8 @positive_biggershl_shlnuwnsw_ashrexact(i8 %x) { 359; CHECK-LABEL: @positive_biggershl_shlnuwnsw_ashrexact( 360; CHECK-NEXT: [[RET:%.*]] = shl nuw nsw i8 [[X:%.*]], 3 361; CHECK-NEXT: ret i8 [[RET]] 362; 363 %tmp0 = ashr exact i8 %x, 3 364 %ret = shl nuw nsw i8 %tmp0, 6 365 ret i8 %ret 366} 367 368; ============================================================================ ; 369; Vector 370; ============================================================================ ; 371 372define <2 x i8> @positive_samevar_vec(<2 x i8> %x, <2 x i8> %y) { 373; CHECK-LABEL: @positive_samevar_vec( 374; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> <i8 -1, i8 -1>, [[Y:%.*]] 375; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], [[X:%.*]] 376; CHECK-NEXT: ret <2 x i8> [[RET]] 377; 378 %tmp0 = ashr <2 x i8> %x, %y 379 %ret = shl <2 x i8> %tmp0, %y 380 ret <2 x i8> %ret 381} 382 383; ============================================================================ ; 384; Constant Vectors 385; ============================================================================ ; 386 387define <2 x i8> @positive_sameconst_vec(<2 x i8> %x) { 388; CHECK-LABEL: @positive_sameconst_vec( 389; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -8, i8 -8> 390; CHECK-NEXT: ret <2 x i8> [[TMP1]] 391; 392 %tmp0 = ashr <2 x i8> %x, <i8 3, i8 3> 393 %ret = shl <2 x i8> %tmp0, <i8 3, i8 3> 394 ret <2 x i8> %ret 395} 396 397define <3 x i8> @positive_sameconst_vec_undef0(<3 x i8> %x) { 398; CHECK-LABEL: @positive_sameconst_vec_undef0( 399; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3> 400; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 3, i8 3, i8 3> 401; CHECK-NEXT: ret <3 x i8> [[RET]] 402; 403 %tmp0 = ashr <3 x i8> %x, <i8 3, i8 undef, i8 3> 404 %ret = shl <3 x i8> %tmp0, <i8 3, i8 3, i8 3> 405 ret <3 x i8> %ret 406} 407 408define <3 x i8> @positive_sameconst_vec_undef1(<3 x i8> %x) { 409; CHECK-LABEL: @positive_sameconst_vec_undef1( 410; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 3, i8 3, i8 3> 411; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 3, i8 undef, i8 3> 412; CHECK-NEXT: ret <3 x i8> [[RET]] 413; 414 %tmp0 = ashr <3 x i8> %x, <i8 3, i8 3, i8 3> 415 %ret = shl <3 x i8> %tmp0, <i8 3, i8 undef, i8 3> 416 ret <3 x i8> %ret 417} 418 419define <3 x i8> @positive_sameconst_vec_undef2(<3 x i8> %x) { 420; CHECK-LABEL: @positive_sameconst_vec_undef2( 421; CHECK-NEXT: [[RET:%.*]] = and <3 x i8> [[X:%.*]], <i8 -8, i8 poison, i8 -8> 422; CHECK-NEXT: ret <3 x i8> [[RET]] 423; 424 %tmp0 = ashr <3 x i8> %x, <i8 3, i8 undef, i8 3> 425 %ret = shl <3 x i8> %tmp0, <i8 3, i8 undef, i8 3> 426 ret <3 x i8> %ret 427} 428 429define <2 x i8> @positive_biggerashr_vec(<2 x i8> %x) { 430; CHECK-LABEL: @positive_biggerashr_vec( 431; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 3, i8 3> 432; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], <i8 -8, i8 -8> 433; CHECK-NEXT: ret <2 x i8> [[RET]] 434; 435 %tmp0 = ashr <2 x i8> %x, <i8 6, i8 6> 436 %ret = shl <2 x i8> %tmp0, <i8 3, i8 3> 437 ret <2 x i8> %ret 438} 439 440define <3 x i8> @positive_biggerashr_vec_undef0(<3 x i8> %x) { 441; CHECK-LABEL: @positive_biggerashr_vec_undef0( 442; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 6, i8 undef, i8 6> 443; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 3, i8 3, i8 3> 444; CHECK-NEXT: ret <3 x i8> [[RET]] 445; 446 %tmp0 = ashr <3 x i8> %x, <i8 6, i8 undef, i8 6> 447 %ret = shl <3 x i8> %tmp0, <i8 3, i8 3, i8 3> 448 ret <3 x i8> %ret 449} 450 451define <3 x i8> @positive_biggerashr_vec_undef1(<3 x i8> %x) { 452; CHECK-LABEL: @positive_biggerashr_vec_undef1( 453; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 6, i8 6, i8 6> 454; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 3, i8 undef, i8 3> 455; CHECK-NEXT: ret <3 x i8> [[RET]] 456; 457 %tmp0 = ashr <3 x i8> %x, <i8 6, i8 6, i8 6> 458 %ret = shl <3 x i8> %tmp0, <i8 3, i8 undef, i8 3> 459 ret <3 x i8> %ret 460} 461 462define <3 x i8> @positive_biggerashr_vec_undef2(<3 x i8> %x) { 463; CHECK-LABEL: @positive_biggerashr_vec_undef2( 464; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 6, i8 undef, i8 6> 465; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 3, i8 undef, i8 3> 466; CHECK-NEXT: ret <3 x i8> [[RET]] 467; 468 %tmp0 = ashr <3 x i8> %x, <i8 6, i8 undef, i8 6> 469 %ret = shl <3 x i8> %tmp0, <i8 3, i8 undef, i8 3> 470 ret <3 x i8> %ret 471} 472 473define <2 x i8> @positive_biggershl_vec(<2 x i8> %x) { 474; CHECK-LABEL: @positive_biggershl_vec( 475; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[X:%.*]], <i8 3, i8 3> 476; CHECK-NEXT: [[RET:%.*]] = and <2 x i8> [[TMP1]], <i8 -64, i8 -64> 477; CHECK-NEXT: ret <2 x i8> [[RET]] 478; 479 %tmp0 = ashr <2 x i8> %x, <i8 3, i8 3> 480 %ret = shl <2 x i8> %tmp0, <i8 6, i8 6> 481 ret <2 x i8> %ret 482} 483 484define <3 x i8> @positive_biggershl_vec_undef0(<3 x i8> %x) { 485; CHECK-LABEL: @positive_biggershl_vec_undef0( 486; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3> 487; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 6, i8 6, i8 6> 488; CHECK-NEXT: ret <3 x i8> [[RET]] 489; 490 %tmp0 = ashr <3 x i8> %x, <i8 3, i8 undef, i8 3> 491 %ret = shl <3 x i8> %tmp0, <i8 6, i8 6, i8 6> 492 ret <3 x i8> %ret 493} 494 495define <3 x i8> @positive_biggershl_vec_undef1(<3 x i8> %x) { 496; CHECK-LABEL: @positive_biggershl_vec_undef1( 497; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 3, i8 3, i8 3> 498; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 6, i8 undef, i8 6> 499; CHECK-NEXT: ret <3 x i8> [[RET]] 500; 501 %tmp0 = ashr <3 x i8> %x, <i8 3, i8 3, i8 3> 502 %ret = shl <3 x i8> %tmp0, <i8 6, i8 undef, i8 6> 503 ret <3 x i8> %ret 504} 505 506define <3 x i8> @positive_biggershl_vec_undef2(<3 x i8> %x) { 507; CHECK-LABEL: @positive_biggershl_vec_undef2( 508; CHECK-NEXT: [[TMP0:%.*]] = ashr <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3> 509; CHECK-NEXT: [[RET:%.*]] = shl <3 x i8> [[TMP0]], <i8 6, i8 undef, i8 6> 510; CHECK-NEXT: ret <3 x i8> [[RET]] 511; 512 %tmp0 = ashr <3 x i8> %x, <i8 3, i8 undef, i8 3> 513 %ret = shl <3 x i8> %tmp0, <i8 6, i8 undef, i8 6> 514 ret <3 x i8> %ret 515} 516 517; ============================================================================ ; 518; Positive multi-use tests with constant 519; ============================================================================ ; 520 521define i8 @positive_sameconst_multiuse(i8 %x) { 522; CHECK-LABEL: @positive_sameconst_multiuse( 523; CHECK-NEXT: [[TMP0:%.*]] = ashr i8 [[X:%.*]], 3 524; CHECK-NEXT: call void @use32(i8 [[TMP0]]) 525; CHECK-NEXT: [[RET:%.*]] = and i8 [[X]], -8 526; CHECK-NEXT: ret i8 [[RET]] 527; 528 %tmp0 = ashr i8 %x, 3 529 call void @use32(i8 %tmp0) 530 %ret = shl i8 %tmp0, 3 531 ret i8 %ret 532} 533 534define i8 @positive_biggerashr_multiuse(i8 %x) { 535; CHECK-LABEL: @positive_biggerashr_multiuse( 536; CHECK-NEXT: [[TMP0:%.*]] = ashr i8 [[X:%.*]], 6 537; CHECK-NEXT: call void @use32(i8 [[TMP0]]) 538; CHECK-NEXT: [[RET:%.*]] = shl nsw i8 [[TMP0]], 3 539; CHECK-NEXT: ret i8 [[RET]] 540; 541 %tmp0 = ashr i8 %x, 6 542 call void @use32(i8 %tmp0) 543 %ret = shl i8 %tmp0, 3 544 ret i8 %ret 545} 546 547define i8 @positive_biggershl_multiuse(i8 %x) { 548; CHECK-LABEL: @positive_biggershl_multiuse( 549; CHECK-NEXT: [[TMP0:%.*]] = ashr i8 [[X:%.*]], 3 550; CHECK-NEXT: call void @use32(i8 [[TMP0]]) 551; CHECK-NEXT: [[RET:%.*]] = shl i8 [[TMP0]], 6 552; CHECK-NEXT: ret i8 [[RET]] 553; 554 %tmp0 = ashr i8 %x, 3 555 call void @use32(i8 %tmp0) 556 %ret = shl i8 %tmp0, 6 557 ret i8 %ret 558} 559 560; ============================================================================ ; 561; Constant Non-Splat Vectors 562; ============================================================================ ; 563 564define <2 x i8> @positive_biggerashr_vec_nonsplat(<2 x i8> %x) { 565; CHECK-LABEL: @positive_biggerashr_vec_nonsplat( 566; CHECK-NEXT: [[TMP0:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 3, i8 3> 567; CHECK-NEXT: [[RET:%.*]] = shl <2 x i8> [[TMP0]], <i8 3, i8 6> 568; CHECK-NEXT: ret <2 x i8> [[RET]] 569; 570 %tmp0 = ashr <2 x i8> %x, <i8 3, i8 3> 571 %ret = shl <2 x i8> %tmp0, <i8 3, i8 6> 572 ret <2 x i8> %ret 573} 574 575define <2 x i8> @positive_biggerLashr_vec_nonsplat(<2 x i8> %x) { 576; CHECK-LABEL: @positive_biggerLashr_vec_nonsplat( 577; CHECK-NEXT: [[TMP0:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 3, i8 6> 578; CHECK-NEXT: [[RET:%.*]] = shl <2 x i8> [[TMP0]], <i8 3, i8 3> 579; CHECK-NEXT: ret <2 x i8> [[RET]] 580; 581 %tmp0 = ashr <2 x i8> %x, <i8 3, i8 6> 582 %ret = shl <2 x i8> %tmp0, <i8 3, i8 3> 583 ret <2 x i8> %ret 584} 585 586; ============================================================================ ; 587; Negative tests. Should not be folded. 588; ============================================================================ ; 589 590define i8 @negative_twovars(i8 %x, i8 %y, i8 %z) { 591; CHECK-LABEL: @negative_twovars( 592; CHECK-NEXT: [[TMP0:%.*]] = ashr i8 [[X:%.*]], [[Y:%.*]] 593; CHECK-NEXT: [[RET:%.*]] = shl i8 [[TMP0]], [[Z:%.*]] 594; CHECK-NEXT: ret i8 [[RET]] 595; 596 %tmp0 = ashr i8 %x, %y 597 %ret = shl i8 %tmp0, %z ; $z, not %y 598 ret i8 %ret 599} 600 601declare void @use32(i8) 602 603; One use only. 604define i8 @negative_oneuse(i8 %x, i8 %y) { 605; CHECK-LABEL: @negative_oneuse( 606; CHECK-NEXT: [[TMP0:%.*]] = ashr i8 [[X:%.*]], [[Y:%.*]] 607; CHECK-NEXT: call void @use32(i8 [[TMP0]]) 608; CHECK-NEXT: [[RET:%.*]] = shl i8 [[TMP0]], [[Y]] 609; CHECK-NEXT: ret i8 [[RET]] 610; 611 %tmp0 = ashr i8 %x, %y 612 call void @use32(i8 %tmp0) 613 %ret = shl i8 %tmp0, %y 614 ret i8 %ret 615} 616