1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4; No selects should remain. 5 6define i41 @zext(i1 %C) { 7; CHECK-LABEL: @zext( 8; CHECK-NEXT: [[V:%.*]] = zext i1 %C to i41 9; CHECK-NEXT: ret i41 [[V]] 10; 11 %V = select i1 %C, i41 1, i41 0 12 ret i41 %V 13} 14 15define i41 @sext(i1 %C) { 16; CHECK-LABEL: @sext( 17; CHECK-NEXT: [[V:%.*]] = sext i1 %C to i41 18; CHECK-NEXT: ret i41 [[V]] 19; 20 %V = select i1 %C, i41 -1, i41 0 21 ret i41 %V 22} 23 24define i999 @not_zext(i1 %C) { 25; CHECK-LABEL: @not_zext( 26; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 %C, true 27; CHECK-NEXT: [[V:%.*]] = zext i1 [[NOT_C]] to i999 28; CHECK-NEXT: ret i999 [[V]] 29; 30 %V = select i1 %C, i999 0, i999 1 31 ret i999 %V 32} 33 34define i999 @not_sext(i1 %C) { 35; CHECK-LABEL: @not_sext( 36; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 %C, true 37; CHECK-NEXT: [[V:%.*]] = sext i1 [[NOT_C]] to i999 38; CHECK-NEXT: ret i999 [[V]] 39; 40 %V = select i1 %C, i999 0, i999 -1 41 ret i999 %V 42} 43 44; Vector selects of vector splat constants match APInt too. 45 46define <2 x i41> @zext_vec(<2 x i1> %C) { 47; CHECK-LABEL: @zext_vec( 48; CHECK-NEXT: [[V:%.*]] = zext <2 x i1> %C to <2 x i41> 49; CHECK-NEXT: ret <2 x i41> [[V]] 50; 51 %V = select <2 x i1> %C, <2 x i41> <i41 1, i41 1>, <2 x i41> <i41 0, i41 0> 52 ret <2 x i41> %V 53} 54 55define <2 x i32> @sext_vec(<2 x i1> %C) { 56; CHECK-LABEL: @sext_vec( 57; CHECK-NEXT: [[V:%.*]] = sext <2 x i1> %C to <2 x i32> 58; CHECK-NEXT: ret <2 x i32> [[V]] 59; 60 %V = select <2 x i1> %C, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 0> 61 ret <2 x i32> %V 62} 63 64define <2 x i999> @not_zext_vec(<2 x i1> %C) { 65; CHECK-LABEL: @not_zext_vec( 66; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> %C, <i1 true, i1 true> 67; CHECK-NEXT: [[V:%.*]] = zext <2 x i1> [[NOT_C]] to <2 x i999> 68; CHECK-NEXT: ret <2 x i999> [[V]] 69; 70 %V = select <2 x i1> %C, <2 x i999> <i999 0, i999 0>, <2 x i999> <i999 1, i999 1> 71 ret <2 x i999> %V 72} 73 74define <2 x i64> @not_sext_vec(<2 x i1> %C) { 75; CHECK-LABEL: @not_sext_vec( 76; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> %C, <i1 true, i1 true> 77; CHECK-NEXT: [[V:%.*]] = sext <2 x i1> [[NOT_C]] to <2 x i64> 78; CHECK-NEXT: ret <2 x i64> [[V]] 79; 80 %V = select <2 x i1> %C, <2 x i64> <i64 0, i64 0>, <2 x i64> <i64 -1, i64 -1> 81 ret <2 x i64> %V 82} 83 84; But don't touch this - we would need 3 instructions to extend and splat the scalar select condition. 85 86define <2 x i32> @scalar_select_of_vectors(i1 %c) { 87; CHECK-LABEL: @scalar_select_of_vectors( 88; CHECK-NEXT: [[V:%.*]] = select i1 %c, <2 x i32> <i32 1, i32 1>, <2 x i32> zeroinitializer 89; CHECK-NEXT: ret <2 x i32> [[V]] 90; 91 %V = select i1 %c, <2 x i32> <i32 1, i32 1>, <2 x i32> zeroinitializer 92 ret <2 x i32> %V 93} 94 95;; (x <s 0) ? -1 : 0 -> ashr x, 31 96 97define i41 @test3(i41 %X) { 98; CHECK-LABEL: @test3( 99; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i41 %X, 40 100; CHECK-NEXT: ret i41 [[X_LOBIT]] 101; 102 %t = icmp slt i41 %X, 0 103 %V = select i1 %t, i41 -1, i41 0 104 ret i41 %V 105} 106 107;; (x <s 0) ? -1 : 0 -> ashr x, 31 108 109define i1023 @test4(i1023 %X) { 110; CHECK-LABEL: @test4( 111; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i1023 %X, 1022 112; CHECK-NEXT: ret i1023 [[X_LOBIT]] 113; 114 %t = icmp slt i1023 %X, 0 115 %V = select i1 %t, i1023 -1, i1023 0 116 ret i1023 %V 117} 118 119