; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -instcombine < %s | FileCheck %s define <4 x i32> @test_FoldShiftByConstant_CreateSHL(<4 x i32> %in) { ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL( ; CHECK-NEXT: [[VSHL_N:%.*]] = mul <4 x i32> [[IN:%.*]], ; CHECK-NEXT: ret <4 x i32> [[VSHL_N]] ; %mul.i = mul <4 x i32> %in, %vshl_n = shl <4 x i32> %mul.i, ret <4 x i32> %vshl_n } define <8 x i16> @test_FoldShiftByConstant_CreateSHL2(<8 x i16> %in) { ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL2( ; CHECK-NEXT: [[VSHL_N:%.*]] = mul <8 x i16> [[IN:%.*]], ; CHECK-NEXT: ret <8 x i16> [[VSHL_N]] ; %mul.i = mul <8 x i16> %in, %vshl_n = shl <8 x i16> %mul.i, ret <8 x i16> %vshl_n } define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) { ; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd( ; CHECK-NEXT: [[TMP1:%.*]] = mul <16 x i8> [[IN0:%.*]], ; CHECK-NEXT: [[VSHL_N:%.*]] = and <16 x i8> [[TMP1]], ; CHECK-NEXT: ret <16 x i8> [[VSHL_N]] ; %vsra_n = ashr <16 x i8> %in0, %tmp = add <16 x i8> %in0, %vsra_n %vshl_n = shl <16 x i8> %tmp, ret <16 x i8> %vshl_n } define i32 @lshr_add_shl(i32 %x, i32 %y) { ; CHECK-LABEL: @lshr_add_shl( ; CHECK-NEXT: [[B1:%.*]] = shl i32 [[Y:%.*]], 4 ; CHECK-NEXT: [[A2:%.*]] = add i32 [[B1]], [[X:%.*]] ; CHECK-NEXT: [[C:%.*]] = and i32 [[A2]], -16 ; CHECK-NEXT: ret i32 [[C]] ; %a = lshr i32 %x, 4 %b = add i32 %a, %y %c = shl i32 %b, 4 ret i32 %c } define <2 x i32> @lshr_add_shl_v2i32(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @lshr_add_shl_v2i32( ; CHECK-NEXT: [[B1:%.*]] = shl <2 x i32> [[Y:%.*]], ; CHECK-NEXT: [[A2:%.*]] = add <2 x i32> [[B1]], [[X:%.*]] ; CHECK-NEXT: [[C:%.*]] = and <2 x i32> [[A2]], ; CHECK-NEXT: ret <2 x i32> [[C]] ; %a = lshr <2 x i32> %x, %b = add <2 x i32> %a, %y %c = shl <2 x i32> %b, ret <2 x i32> %c } define <2 x i32> @lshr_add_shl_v2i32_undef(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @lshr_add_shl_v2i32_undef( ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[B:%.*]] = add <2 x i32> [[A]], [[Y:%.*]] ; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], ; CHECK-NEXT: ret <2 x i32> [[C]] ; %a = lshr <2 x i32> %x, %b = add <2 x i32> %a, %y %c = shl <2 x i32> %b, ret <2 x i32> %c } define <2 x i32> @lshr_add_shl_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @lshr_add_shl_v2i32_nonuniform( ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[B:%.*]] = add <2 x i32> [[A]], [[Y:%.*]] ; CHECK-NEXT: [[C:%.*]] = shl <2 x i32> [[B]], ; CHECK-NEXT: ret <2 x i32> [[C]] ; %a = lshr <2 x i32> %x, %b = add <2 x i32> %a, %y %c = shl <2 x i32> %b, ret <2 x i32> %c } define i32 @lshr_add_and_shl(i32 %x, i32 %y) { ; CHECK-LABEL: @lshr_add_and_shl( ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[Y:%.*]], 5 ; CHECK-NEXT: [[X_MASK:%.*]] = and i32 [[X:%.*]], 4064 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[X_MASK]], [[TMP1]] ; CHECK-NEXT: ret i32 [[TMP2]] ; %1 = lshr i32 %x, 5 %2 = and i32 %1, 127 %3 = add i32 %y, %2 %4 = shl i32 %3, 5 ret i32 %4 } define <2 x i32> @lshr_add_and_shl_v2i32(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @lshr_add_and_shl_v2i32( ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[Y:%.*]], ; CHECK-NEXT: [[X_MASK:%.*]] = and <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i32> [[X_MASK]], [[TMP1]] ; CHECK-NEXT: ret <2 x i32> [[TMP2]] ; %1 = lshr <2 x i32> %x, %2 = and <2 x i32> %1, %3 = add <2 x i32> %y, %2 %4 = shl <2 x i32> %3, ret <2 x i32> %4 } define <2 x i32> @lshr_add_and_shl_v2i32_undef(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @lshr_add_and_shl_v2i32_undef( ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], ; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]] ; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], ; CHECK-NEXT: ret <2 x i32> [[TMP4]] ; %1 = lshr <2 x i32> %x, %2 = and <2 x i32> %1, %3 = add <2 x i32> %y, %2 %4 = shl <2 x i32> %3, ret <2 x i32> %4 } define <2 x i32> @lshr_add_and_shl_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @lshr_add_and_shl_v2i32_nonuniform( ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], ; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> [[TMP2]], [[Y:%.*]] ; CHECK-NEXT: [[TMP4:%.*]] = shl <2 x i32> [[TMP3]], ; CHECK-NEXT: ret <2 x i32> [[TMP4]] ; %1 = lshr <2 x i32> %x, %2 = and <2 x i32> %1, %3 = add <2 x i32> %y, %2 %4 = shl <2 x i32> %3, ret <2 x i32> %4 } define i32 @shl_add_and_lshr(i32 %x, i32 %y) { ; CHECK-LABEL: @shl_add_and_lshr( ; CHECK-NEXT: [[C1:%.*]] = shl i32 [[Y:%.*]], 4 ; CHECK-NEXT: [[X_MASK:%.*]] = and i32 [[X:%.*]], 128 ; CHECK-NEXT: [[D:%.*]] = add i32 [[X_MASK]], [[C1]] ; CHECK-NEXT: ret i32 [[D]] ; %a = lshr i32 %x, 4 %b = and i32 %a, 8 %c = add i32 %b, %y %d = shl i32 %c, 4 ret i32 %d } define <2 x i32> @shl_add_and_lshr_v2i32(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @shl_add_and_lshr_v2i32( ; CHECK-NEXT: [[C1:%.*]] = shl <2 x i32> [[Y:%.*]], ; CHECK-NEXT: [[X_MASK:%.*]] = and <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[D:%.*]] = add <2 x i32> [[X_MASK]], [[C1]] ; CHECK-NEXT: ret <2 x i32> [[D]] ; %a = lshr <2 x i32> %x, %b = and <2 x i32> %a, %c = add <2 x i32> %b, %y %d = shl <2 x i32> %c, ret <2 x i32> %d } define <2 x i32> @shl_add_and_lshr_v2i32_undef(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @shl_add_and_lshr_v2i32_undef( ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], ; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]] ; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], ; CHECK-NEXT: ret <2 x i32> [[D]] ; %a = lshr <2 x i32> %x, %b = and <2 x i32> %a, %c = add <2 x i32> %b, %y %d = shl <2 x i32> %c, ret <2 x i32> %d } define <2 x i32> @shl_add_and_lshr_v2i32_nonuniform(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @shl_add_and_lshr_v2i32_nonuniform( ; CHECK-NEXT: [[A:%.*]] = lshr <2 x i32> [[X:%.*]], ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[A]], ; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], [[Y:%.*]] ; CHECK-NEXT: [[D:%.*]] = shl <2 x i32> [[C]], ; CHECK-NEXT: ret <2 x i32> [[D]] ; %a = lshr <2 x i32> %x, %b = and <2 x i32> %a, %c = add <2 x i32> %b, %y %d = shl <2 x i32> %c, ret <2 x i32> %d }