From: Sanjay Patel Date: Tue, 7 Dec 2021 16:28:23 +0000 (-0500) Subject: [InstCombine] add tests for div with select-of-constants divisor; NFC X-Git-Tag: upstream/15.0.7~23726 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfde8a6c9da284ccd048fcbf38d4c2470d614d2c;p=platform%2Fupstream%2Fllvm.git [InstCombine] add tests for div with select-of-constants divisor; NFC Similar patterns as tests for: D115173 (and we might want to make a single patch for all of these). --- diff --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll index ba8dbb9..858d7db 100644 --- a/llvm/test/Transforms/InstCombine/div.ll +++ b/llvm/test/Transforms/InstCombine/div.ll @@ -1,8 +1,8 @@ ; 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:%.*]] @@ -1087,3 +1087,179 @@ define @sdiv_by_minSigned_nxv2i8( %x) { %sub = sub zeroinitializer, %div ret %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> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = sdiv <2 x i8> , [[S]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %s = select i1 %b, <2 x i8> , <2 x i8> + %r = sdiv <2 x i8> , %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> +; + %s = select i1 %b, <2 x i8> , <2 x i8> + %r = sdiv <2 x i8> , %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> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = sdiv <2 x i8> , [[S]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %s = select i1 %b, <2 x i8> , <2 x i8> + %r = sdiv <2 x i8> , %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> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = udiv <2 x i8> , [[S]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %s = select i1 %b, <2 x i8> , <2 x i8> + %r = udiv <2 x i8> , %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> +; + %s = select i1 %b, <2 x i8> , <2 x i8> + %r = udiv <2 x i8> , %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> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = udiv <2 x i8> , [[S]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %s = select i1 %b, <2 x i8> , <2 x i8> + %r = udiv <2 x i8> , %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 +}