Skip to content

Commit

Permalink
[InstCombine] add tests for sdiv-of-abs; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Aug 17, 2020
1 parent 6cd4a6f commit 61512dd
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions llvm/test/Transforms/InstCombine/sdiv-canonicalize.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s

declare void @use(i32)
declare i32 @llvm.abs.i32(i32, i1)
declare <4 x i32> @llvm.abs.v4i32(<4 x i32>, i1)

define i32 @test_sdiv_canonicalize_op0(i32 %x, i32 %y) {
; CHECK-LABEL: @test_sdiv_canonicalize_op0(
; CHECK-NEXT: [[SDIV1:%.*]] = sdiv i32 [[X:%.*]], [[Y:%.*]]
Expand Down Expand Up @@ -89,3 +93,49 @@ define i64 @test_sdiv_canonicalize_constexpr(i64 %L1) {
%B4 = sdiv i64 %L1, %B8
ret i64 %B4
}

define i32 @sdiv_abs_nsw(i32 %x) {
; CHECK-LABEL: @sdiv_abs_nsw(
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
; CHECK-NEXT: [[R:%.*]] = sdiv i32 [[A]], [[X]]
; CHECK-NEXT: ret i32 [[R]]
;
%a = call i32 @llvm.abs.i32(i32 %x, i1 true)
%r = sdiv i32 %a, %x
ret i32 %r
}

define <4 x i32> @sdiv_abs_nsw_vec(<4 x i32> %x) {
; CHECK-LABEL: @sdiv_abs_nsw_vec(
; CHECK-NEXT: [[A:%.*]] = call <4 x i32> @llvm.abs.v4i32(<4 x i32> [[X:%.*]], i1 true)
; CHECK-NEXT: [[R:%.*]] = sdiv <4 x i32> [[X]], [[A]]
; CHECK-NEXT: ret <4 x i32> [[R]]
;
%a = call <4 x i32> @llvm.abs.v4i32(<4 x i32> %x, i1 true)
%r = sdiv <4 x i32> %x, %a
ret <4 x i32> %r
}

define i32 @sdiv_abs(i32 %x) {
; CHECK-LABEL: @sdiv_abs(
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
; CHECK-NEXT: [[R:%.*]] = sdiv i32 [[A]], [[X]]
; CHECK-NEXT: ret i32 [[R]]
;
%a = call i32 @llvm.abs.i32(i32 %x, i1 false)
%r = sdiv i32 %a, %x
ret i32 %r
}

define i32 @sdiv_abs_extra_use(i32 %x) {
; CHECK-LABEL: @sdiv_abs_extra_use(
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
; CHECK-NEXT: call void @use(i32 [[A]])
; CHECK-NEXT: [[R:%.*]] = sdiv i32 [[A]], [[X]]
; CHECK-NEXT: ret i32 [[R]]
;
%a = call i32 @llvm.abs.i32(i32 %x, i1 true)
call void @use(i32 %a)
%r = sdiv i32 %a, %x
ret i32 %r
}

0 comments on commit 61512dd

Please sign in to comment.