; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; This test makes sure that div instructions are properly eliminated.
-
; RUN: opt < %s -instcombine -S | FileCheck %s
+declare void @use(i32)
+
define i32 @test1(i32 %A) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i32 [[A:%.*]]
%sub = sub <vscale x 2 x i8> zeroinitializer, %div
ret <vscale x 2 x i8> %sub
}
+
+define i32 @sdiv_constant_dividend_select_of_constants_divisor(i1 %b) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_of_constants_divisor(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
+; CHECK-NEXT: [[R:%.*]] = sdiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 -3
+ %r = sdiv i32 42, %s
+ ret i32 %r
+}
+
+define i32 @sdiv_constant_dividend_select_of_constants_divisor_use(i1 %b) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_of_constants_divisor_use(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
+; CHECK-NEXT: call void @use(i32 [[S]])
+; CHECK-NEXT: [[R:%.*]] = sdiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 -3
+ call void @use(i32 %s)
+ %r = sdiv i32 42, %s
+ ret i32 %r
+}
+
+define i32 @sdiv_constant_dividend_select_divisor1(i1 %b, i32 %x) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_divisor1(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 [[X:%.*]], i32 -3
+; CHECK-NEXT: [[R:%.*]] = sdiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 %x, i32 -3
+ %r = sdiv i32 42, %s
+ ret i32 %r
+}
+
+define i32 @sdiv_constant_dividend_select_divisor2(i1 %b, i32 %x) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_divisor2(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = sdiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 %x
+ %r = sdiv i32 42, %s
+ ret i32 %r
+}
+
+define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_of_constants_divisor_vec(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>
+; CHECK-NEXT: [[R:%.*]] = sdiv <2 x i8> <i8 42, i8 -42>, [[S]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>
+ %r = sdiv <2 x i8> <i8 42, i8 -42>, %s
+ ret <2 x i8> %r
+}
+
+define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_of_constants_divisor_vec_ub1(
+; CHECK-NEXT: ret <2 x i8> <i8 -10, i8 -10>
+;
+ %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>
+ %r = sdiv <2 x i8> <i8 42, i8 -42>, %s
+ ret <2 x i8> %r
+}
+
+define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec_ub2(i1 %b) {
+; CHECK-LABEL: @sdiv_constant_dividend_select_of_constants_divisor_vec_ub2(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 -1>
+; CHECK-NEXT: [[R:%.*]] = sdiv <2 x i8> <i8 42, i8 -128>, [[S]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 -1>
+ %r = sdiv <2 x i8> <i8 42, i8 -128>, %s
+ ret <2 x i8> %r
+}
+
+define i32 @sdiv_select_of_constants_divisor(i1 %b, i32 %x) {
+; CHECK-LABEL: @sdiv_select_of_constants_divisor(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
+; CHECK-NEXT: [[R:%.*]] = sdiv i32 [[X:%.*]], [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 -3
+ %r = sdiv i32 %x, %s
+ ret i32 %r
+}
+
+define i32 @udiv_constant_dividend_select_of_constants_divisor(i1 %b) {
+; CHECK-LABEL: @udiv_constant_dividend_select_of_constants_divisor(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
+; CHECK-NEXT: [[R:%.*]] = udiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 -3
+ %r = udiv i32 42, %s
+ ret i32 %r
+}
+
+define i32 @udiv_constant_dividend_select_of_constants_divisor_use(i1 %b) {
+; CHECK-LABEL: @udiv_constant_dividend_select_of_constants_divisor_use(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
+; CHECK-NEXT: call void @use(i32 [[S]])
+; CHECK-NEXT: [[R:%.*]] = udiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 -3
+ call void @use(i32 %s)
+ %r = udiv i32 42, %s
+ ret i32 %r
+}
+
+define i32 @udiv_constant_dividend_select_divisor1(i1 %b, i32 %x) {
+; CHECK-LABEL: @udiv_constant_dividend_select_divisor1(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 [[X:%.*]], i32 -3
+; CHECK-NEXT: [[R:%.*]] = udiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 %x, i32 -3
+ %r = udiv i32 42, %s
+ ret i32 %r
+}
+
+define i32 @udiv_constant_dividend_select_divisor2(i1 %b, i32 %x) {
+; CHECK-LABEL: @udiv_constant_dividend_select_divisor2(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = udiv i32 42, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 %x
+ %r = udiv i32 42, %s
+ ret i32 %r
+}
+
+define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {
+; CHECK-LABEL: @udiv_constant_dividend_select_of_constants_divisor_vec(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>
+; CHECK-NEXT: [[R:%.*]] = udiv <2 x i8> <i8 42, i8 -42>, [[S]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>
+ %r = udiv <2 x i8> <i8 42, i8 -42>, %s
+ ret <2 x i8> %r
+}
+
+define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {
+; CHECK-LABEL: @udiv_constant_dividend_select_of_constants_divisor_vec_ub1(
+; CHECK-NEXT: ret <2 x i8> <i8 0, i8 53>
+;
+ %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>
+ %r = udiv <2 x i8> <i8 42, i8 -42>, %s
+ ret <2 x i8> %r
+}
+
+define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec_ub2(i1 %b) {
+; CHECK-LABEL: @udiv_constant_dividend_select_of_constants_divisor_vec_ub2(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 -1>
+; CHECK-NEXT: [[R:%.*]] = udiv <2 x i8> <i8 42, i8 -128>, [[S]]
+; CHECK-NEXT: ret <2 x i8> [[R]]
+;
+ %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 -1>
+ %r = udiv <2 x i8> <i8 42, i8 -128>, %s
+ ret <2 x i8> %r
+}
+
+define i32 @udiv_select_of_constants_divisor(i1 %b, i32 %x) {
+; CHECK-LABEL: @udiv_select_of_constants_divisor(
+; CHECK-NEXT: [[S:%.*]] = select i1 [[B:%.*]], i32 12, i32 -3
+; CHECK-NEXT: [[R:%.*]] = udiv i32 [[X:%.*]], [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %s = select i1 %b, i32 12, i32 -3
+ %r = udiv i32 %x, %s
+ ret i32 %r
+}