120 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S -o - | FileCheck %s3 4; This test case was added as a reproducer for a miscompile, where instcombine5; introduced an6; srem <2 x i16> %1, <i16 undef, i16 2>7; instruction, which makes the whole srem undefined (even if we only end up8; extracting the second element in the vector).9define i16 @test_srem_orig(i16 %a, i1 %cmp) {10; CHECK-LABEL: @test_srem_orig(11; CHECK-NEXT: [[TMP1:%.*]] = srem i16 [[A:%.*]], 212; CHECK-NEXT: [[T3:%.*]] = select i1 [[CMP:%.*]], i16 1, i16 [[TMP1]]13; CHECK-NEXT: ret i16 [[T3]]14;15 %splatinsert = insertelement <2 x i16> undef, i16 %a, i32 016 %splat = shufflevector <2 x i16> %splatinsert, <2 x i16> undef, <2 x i32> zeroinitializer17 %t1 = select i1 %cmp, <2 x i16> <i16 1, i16 1>, <2 x i16> %splat18 %t2 = srem <2 x i16> %t1, <i16 2, i16 2>19 %t3 = extractelement <2 x i16> %t2, i32 120 ret i16 %t321}22 23; This is basically a reduced version of test_srem_orig (based on what the24; code would look like after a few iterations of instcombine, just before we25; try to transform the shufflevector by doing26; "evaluateInDifferentElementOrder".27define <2 x i16> @test_srem(i16 %a, i1 %cmp) {28; CHECK-LABEL: @test_srem(29; CHECK-NEXT: [[SPLATINSERT:%.*]] = insertelement <2 x i16> <i16 poison, i16 undef>, i16 [[A:%.*]], i64 030; CHECK-NEXT: [[T1:%.*]] = srem <2 x i16> [[SPLATINSERT]], <i16 2, i16 1>31; CHECK-NEXT: [[SPLAT_OP:%.*]] = shufflevector <2 x i16> [[T1]], <2 x i16> poison, <2 x i32> <i32 poison, i32 0>32; CHECK-NEXT: [[T2:%.*]] = select i1 [[CMP:%.*]], <2 x i16> <i16 77, i16 99>, <2 x i16> [[SPLAT_OP]]33; CHECK-NEXT: ret <2 x i16> [[T2]]34;35 %splatinsert = insertelement <2 x i16> undef, i16 %a, i32 036 %t1 = srem <2 x i16> %splatinsert, <i16 2, i16 1>37 %splat.op = shufflevector <2 x i16> %t1, <2 x i16> undef, <2 x i32> <i32 undef, i32 0>38 %t2 = select i1 %cmp, <2 x i16> <i16 77, i16 99>, <2 x i16> %splat.op39 ret <2 x i16> %t240}41 42define <2 x i16> @test_urem(i16 %a, i1 %cmp) {43; CHECK-LABEL: @test_urem(44; CHECK-NEXT: [[SPLATINSERT:%.*]] = insertelement <2 x i16> <i16 poison, i16 undef>, i16 [[A:%.*]], i64 045; CHECK-NEXT: [[T1:%.*]] = urem <2 x i16> [[SPLATINSERT]], <i16 3, i16 1>46; CHECK-NEXT: [[SPLAT_OP:%.*]] = shufflevector <2 x i16> [[T1]], <2 x i16> poison, <2 x i32> <i32 poison, i32 0>47; CHECK-NEXT: [[T2:%.*]] = select i1 [[CMP:%.*]], <2 x i16> <i16 77, i16 99>, <2 x i16> [[SPLAT_OP]]48; CHECK-NEXT: ret <2 x i16> [[T2]]49;50 %splatinsert = insertelement <2 x i16> undef, i16 %a, i32 051 %t1 = urem <2 x i16> %splatinsert, <i16 3, i16 1>52 %splat.op = shufflevector <2 x i16> %t1, <2 x i16> undef, <2 x i32> <i32 undef, i32 0>53 %t2 = select i1 %cmp, <2 x i16> <i16 77, i16 99>, <2 x i16> %splat.op54 ret <2 x i16> %t255}56 57define <2 x i16> @test_sdiv(i16 %a, i1 %cmp) {58; CHECK-LABEL: @test_sdiv(59; CHECK-NEXT: [[SPLATINSERT:%.*]] = insertelement <2 x i16> <i16 poison, i16 undef>, i16 [[A:%.*]], i64 060; CHECK-NEXT: [[T1:%.*]] = sdiv <2 x i16> [[SPLATINSERT]], <i16 2, i16 1>61; CHECK-NEXT: [[SPLAT_OP:%.*]] = shufflevector <2 x i16> [[T1]], <2 x i16> poison, <2 x i32> <i32 poison, i32 0>62; CHECK-NEXT: [[T2:%.*]] = select i1 [[CMP:%.*]], <2 x i16> <i16 77, i16 99>, <2 x i16> [[SPLAT_OP]]63; CHECK-NEXT: ret <2 x i16> [[T2]]64;65 %splatinsert = insertelement <2 x i16> undef, i16 %a, i32 066 %t1 = sdiv <2 x i16> %splatinsert, <i16 2, i16 1>67 %splat.op = shufflevector <2 x i16> %t1, <2 x i16> undef, <2 x i32> <i32 undef, i32 0>68 %t2 = select i1 %cmp, <2 x i16> <i16 77, i16 99>, <2 x i16> %splat.op69 ret <2 x i16> %t270}71 72define <2 x i16> @test_udiv(i16 %a, i1 %cmp) {73; CHECK-LABEL: @test_udiv(74; CHECK-NEXT: [[SPLATINSERT:%.*]] = insertelement <2 x i16> <i16 poison, i16 undef>, i16 [[A:%.*]], i64 075; CHECK-NEXT: [[T1:%.*]] = udiv <2 x i16> [[SPLATINSERT]], <i16 3, i16 1>76; CHECK-NEXT: [[SPLAT_OP:%.*]] = shufflevector <2 x i16> [[T1]], <2 x i16> poison, <2 x i32> <i32 poison, i32 0>77; CHECK-NEXT: [[T2:%.*]] = select i1 [[CMP:%.*]], <2 x i16> <i16 77, i16 99>, <2 x i16> [[SPLAT_OP]]78; CHECK-NEXT: ret <2 x i16> [[T2]]79;80 %splatinsert = insertelement <2 x i16> undef, i16 %a, i32 081 %t1 = udiv <2 x i16> %splatinsert, <i16 3, i16 1>82 %splat.op = shufflevector <2 x i16> %t1, <2 x i16> undef, <2 x i32> <i32 undef, i32 0>83 %t2 = select i1 %cmp, <2 x i16> <i16 77, i16 99>, <2 x i16> %splat.op84 ret <2 x i16> %t285}86 87; For fdiv we do not need to worry about div by undef. Verify that the88; shufflevector is eliminated here.89define <2 x float> @test_fdiv(float %a, float %b, i1 %cmp) {90; CHECK-LABEL: @test_fdiv(91; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> poison, float [[A:%.*]], i64 192; CHECK-NEXT: [[SPLAT_OP:%.*]] = fdiv <2 x float> [[TMP1]], <float undef, float 3.000000e+00>93; CHECK-NEXT: [[T2:%.*]] = select i1 [[CMP:%.*]], <2 x float> <float 7.700000e+01, float 9.900000e+01>, <2 x float> [[SPLAT_OP]]94; CHECK-NEXT: ret <2 x float> [[T2]]95;96 %splatinsert = insertelement <2 x float> undef, float %a, i32 097 %denom = insertelement <2 x float> <float 3.0, float undef>, float 1.0, i32 198 %t1 = fdiv <2 x float> %splatinsert, %denom99 %splat.op = shufflevector <2 x float> %t1, <2 x float> undef, <2 x i32> <i32 undef, i32 0>100 %t2 = select i1 %cmp, <2 x float> <float 77.0, float 99.0>, <2 x float> %splat.op101 ret <2 x float> %t2102}103 104; For frem we do not need to worry about div by undef. Verify that the105; shufflevector is eliminated here.106define <2 x float> @test_frem(float %a, float %b, i1 %cmp) {107; CHECK-LABEL: @test_frem(108; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> poison, float [[A:%.*]], i64 1109; CHECK-NEXT: [[SPLAT_OP:%.*]] = frem <2 x float> [[TMP1]], <float undef, float 3.000000e+00>110; CHECK-NEXT: [[T2:%.*]] = select i1 [[CMP:%.*]], <2 x float> <float 7.700000e+01, float 9.900000e+01>, <2 x float> [[SPLAT_OP]]111; CHECK-NEXT: ret <2 x float> [[T2]]112;113 %splatinsert = insertelement <2 x float> undef, float %a, i32 0114 %denom = insertelement <2 x float> <float 3.0, float undef>, float 1.0, i32 1115 %t1 = frem <2 x float> %splatinsert, %denom116 %splat.op = shufflevector <2 x float> %t1, <2 x float> undef, <2 x i32> <i32 undef, i32 0>117 %t2 = select i1 %cmp, <2 x float> <float 77.0, float 99.0>, <2 x float> %splat.op118 ret <2 x float> %t2119}120