119 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; No selects should remain.5 6define i41 @zext(i1 %C) {7; CHECK-LABEL: @zext(8; CHECK-NEXT: [[V:%.*]] = zext i1 [[C:%.*]] to i419; CHECK-NEXT: ret i41 [[V]]10;11 %V = select i1 %C, i41 1, i41 012 ret i41 %V13}14 15define i41 @sext(i1 %C) {16; CHECK-LABEL: @sext(17; CHECK-NEXT: [[V:%.*]] = sext i1 [[C:%.*]] to i4118; CHECK-NEXT: ret i41 [[V]]19;20 %V = select i1 %C, i41 -1, i41 021 ret i41 %V22}23 24define i999 @not_zext(i1 %C) {25; CHECK-LABEL: @not_zext(26; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true27; CHECK-NEXT: [[V:%.*]] = zext i1 [[NOT_C]] to i99928; CHECK-NEXT: ret i999 [[V]]29;30 %V = select i1 %C, i999 0, i999 131 ret i999 %V32}33 34define i999 @not_sext(i1 %C) {35; CHECK-LABEL: @not_sext(36; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true37; CHECK-NEXT: [[V:%.*]] = sext i1 [[NOT_C]] to i99938; CHECK-NEXT: ret i999 [[V]]39;40 %V = select i1 %C, i999 0, i999 -141 ret i999 %V42}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> %V53}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> %V62}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:%.*]], splat (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> %V72}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:%.*]], splat (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> %V82}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> splat (i32 1), <2 x i32> zeroinitializer89; CHECK-NEXT: ret <2 x i32> [[V]]90;91 %V = select i1 %c, <2 x i32> <i32 1, i32 1>, <2 x i32> zeroinitializer92 ret <2 x i32> %V93}94 95;; (x <s 0) ? -1 : 0 -> ashr x, 3196 97define i41 @test3(i41 %X) {98; CHECK-LABEL: @test3(99; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i41 [[X:%.*]], 40100; CHECK-NEXT: ret i41 [[X_LOBIT]]101;102 %t = icmp slt i41 %X, 0103 %V = select i1 %t, i41 -1, i41 0104 ret i41 %V105}106 107;; (x <s 0) ? -1 : 0 -> ashr x, 31108 109define i1023 @test4(i1023 %X) {110; CHECK-LABEL: @test4(111; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i1023 [[X:%.*]], 1022112; CHECK-NEXT: ret i1023 [[X_LOBIT]]113;114 %t = icmp slt i1023 %X, 0115 %V = select i1 %t, i1023 -1, i1023 0116 ret i1023 %V117}118 119