2002-05-06 13:35:20 +08:00
|
|
|
; This test makes sure that div instructions are properly eliminated.
|
|
|
|
|
2011-05-01 02:15:53 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2002-05-06 13:35:20 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test1(i32 %A) {
|
|
|
|
%B = sdiv i32 %A, 1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 %A
|
2003-02-19 03:16:45 +08:00
|
|
|
}
|
2003-02-19 03:28:47 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test2(i32 %A) {
|
|
|
|
; => Shift
|
|
|
|
%B = udiv i32 %A, 8 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: lshr i32 %A, 3
|
2003-02-19 03:28:47 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test3(i32 %A) {
|
|
|
|
; => 0, don't need to keep traps
|
|
|
|
%B = sdiv i32 0, %A ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 0
|
2003-02-19 03:28:47 +08:00
|
|
|
}
|
2004-04-26 22:01:47 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test4(i32 %A) {
|
|
|
|
; 0-A
|
|
|
|
%B = sdiv i32 %A, -1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: sub i32 0, %A
|
2004-04-26 22:01:47 +08:00
|
|
|
}
|
2004-09-29 02:21:01 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test5(i32 %A) {
|
|
|
|
%B = udiv i32 %A, -16 ; <i32> [#uses=1]
|
|
|
|
%C = udiv i32 %B, -4 ; <i32> [#uses=1]
|
|
|
|
ret i32 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 0
|
2004-09-29 02:21:01 +08:00
|
|
|
}
|
2004-09-30 01:37:07 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i1 @test6(i32 %A) {
|
|
|
|
%B = udiv i32 %A, 123 ; <i32> [#uses=1]
|
|
|
|
; A < 123
|
|
|
|
%C = icmp eq i32 %B, 0 ; <i1> [#uses=1]
|
|
|
|
ret i1 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test6(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: icmp ult i32 %A, 123
|
2008-03-18 11:45:45 +08:00
|
|
|
}
|
2004-09-30 01:37:07 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i1 @test7(i32 %A) {
|
|
|
|
%B = udiv i32 %A, 10 ; <i32> [#uses=1]
|
|
|
|
; A >= 20 && A < 30
|
|
|
|
%C = icmp eq i32 %B, 2 ; <i1> [#uses=1]
|
|
|
|
ret i1 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test7(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: add i32 %A, -20
|
|
|
|
; CHECK-NEXT: icmp ult i32
|
2004-09-30 01:37:07 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i1 @test8(i8 %A) {
|
|
|
|
%B = udiv i8 %A, 123 ; <i8> [#uses=1]
|
|
|
|
; A >= 246
|
|
|
|
%C = icmp eq i8 %B, 2 ; <i1> [#uses=1]
|
|
|
|
ret i1 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test8(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: icmp ugt i8 %A, -11
|
2008-03-18 11:45:45 +08:00
|
|
|
}
|
2004-09-30 01:37:07 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i1 @test9(i8 %A) {
|
|
|
|
%B = udiv i8 %A, 123 ; <i8> [#uses=1]
|
|
|
|
; A < 246
|
|
|
|
%C = icmp ne i8 %B, 2 ; <i1> [#uses=1]
|
|
|
|
ret i1 %C
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test9(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: icmp ult i8 %A, -10
|
2008-03-18 11:45:45 +08:00
|
|
|
}
|
2004-09-30 01:37:07 +08:00
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test10(i32 %X, i1 %C) {
|
|
|
|
%V = select i1 %C, i32 64, i32 8 ; <i32> [#uses=1]
|
|
|
|
%R = udiv i32 %X, %V ; <i32> [#uses=1]
|
|
|
|
ret i32 %R
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test10(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: select i1 %C, i32 6, i32 3
|
|
|
|
; CHECK-NEXT: lshr i32 %X
|
2004-12-13 05:40:22 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:45:45 +08:00
|
|
|
define i32 @test11(i32 %X, i1 %C) {
|
|
|
|
%A = select i1 %C, i32 1024, i32 32 ; <i32> [#uses=1]
|
|
|
|
%B = udiv i32 %X, %A ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test11(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: select i1 %C, i32 10, i32 5
|
|
|
|
; CHECK-NEXT: lshr i32 %X
|
2006-02-05 15:52:47 +08:00
|
|
|
}
|
2008-05-16 10:59:42 +08:00
|
|
|
|
|
|
|
; PR2328
|
|
|
|
define i32 @test12(i32 %x) nounwind {
|
|
|
|
%tmp3 = udiv i32 %x, %x ; 1
|
|
|
|
ret i32 %tmp3
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test12(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 1
|
2008-05-16 10:59:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test13(i32 %x) nounwind {
|
|
|
|
%tmp3 = sdiv i32 %x, %x ; 1
|
|
|
|
ret i32 %tmp3
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test13(
|
2011-05-01 02:15:53 +08:00
|
|
|
; CHECK-NEXT: ret i32 1
|
2008-05-16 10:59:42 +08:00
|
|
|
}
|
|
|
|
|
2011-05-01 02:16:00 +08:00
|
|
|
define i32 @test14(i8 %x) nounwind {
|
|
|
|
%zext = zext i8 %x to i32
|
|
|
|
%div = udiv i32 %zext, 257 ; 0
|
|
|
|
ret i32 %div
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test14(
|
2011-05-01 02:16:00 +08:00
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
}
|
Carve out a place in instcombine to put transformations which work knowing that their
result is non-zero. Implement an example optimization (PR9814), which allows us to
transform:
A / ((1 << B) >>u 2)
into:
A >>u (B-2)
which we compile into:
_divu3: ## @divu3
leal -2(%rsi), %ecx
shrl %cl, %edi
movl %edi, %eax
ret
instead of:
_divu3: ## @divu3
movb %sil, %cl
movl $1, %esi
shll %cl, %esi
shrl $2, %esi
movl %edi, %eax
xorl %edx, %edx
divl %esi, %eax
ret
llvm-svn: 131860
2011-05-23 02:18:41 +08:00
|
|
|
|
|
|
|
; PR9814
|
|
|
|
define i32 @test15(i32 %a, i32 %b) nounwind {
|
|
|
|
%shl = shl i32 1, %b
|
|
|
|
%div = lshr i32 %shl, 2
|
|
|
|
%div2 = udiv i32 %a, %div
|
|
|
|
ret i32 %div2
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test15(
|
Carve out a place in instcombine to put transformations which work knowing that their
result is non-zero. Implement an example optimization (PR9814), which allows us to
transform:
A / ((1 << B) >>u 2)
into:
A >>u (B-2)
which we compile into:
_divu3: ## @divu3
leal -2(%rsi), %ecx
shrl %cl, %edi
movl %edi, %eax
ret
instead of:
_divu3: ## @divu3
movb %sil, %cl
movl $1, %esi
shll %cl, %esi
shrl $2, %esi
movl %edi, %eax
xorl %edx, %edx
divl %esi, %eax
ret
llvm-svn: 131860
2011-05-23 02:18:41 +08:00
|
|
|
; CHECK-NEXT: add i32 %b, -2
|
|
|
|
; CHECK-NEXT: lshr i32 %a,
|
|
|
|
; CHECK-NEXT: ret i32
|
|
|
|
}
|
|
|
|
|
2014-01-19 23:24:22 +08:00
|
|
|
define <2 x i64> @test16(<2 x i64> %x) nounwind {
|
2014-10-14 05:48:30 +08:00
|
|
|
%shr = lshr <2 x i64> %x, <i64 5, i64 5>
|
|
|
|
%div = udiv <2 x i64> %shr, <i64 6, i64 6>
|
2014-01-19 23:24:22 +08:00
|
|
|
ret <2 x i64> %div
|
|
|
|
; CHECK-LABEL: @test16(
|
2014-10-14 05:48:30 +08:00
|
|
|
; CHECK-NEXT: udiv <2 x i64> %x, <i64 192, i64 192>
|
2014-01-19 23:24:22 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i64>
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i64> @test17(<2 x i64> %x) nounwind {
|
|
|
|
%neg = sub nsw <2 x i64> zeroinitializer, %x
|
|
|
|
%div = sdiv <2 x i64> %neg, <i64 3, i64 4>
|
|
|
|
ret <2 x i64> %div
|
|
|
|
; CHECK-LABEL: @test17(
|
|
|
|
; CHECK-NEXT: sdiv <2 x i64> %x, <i64 -3, i64 -4>
|
|
|
|
; CHECK-NEXT: ret <2 x i64>
|
|
|
|
}
|
Carve out a place in instcombine to put transformations which work knowing that their
result is non-zero. Implement an example optimization (PR9814), which allows us to
transform:
A / ((1 << B) >>u 2)
into:
A >>u (B-2)
which we compile into:
_divu3: ## @divu3
leal -2(%rsi), %ecx
shrl %cl, %edi
movl %edi, %eax
ret
instead of:
_divu3: ## @divu3
movb %sil, %cl
movl $1, %esi
shll %cl, %esi
shrl $2, %esi
movl %edi, %eax
xorl %edx, %edx
divl %esi, %eax
ret
llvm-svn: 131860
2011-05-23 02:18:41 +08:00
|
|
|
|
2014-01-19 23:24:22 +08:00
|
|
|
define <2 x i64> @test18(<2 x i64> %x) nounwind {
|
|
|
|
%div = sdiv <2 x i64> %x, <i64 -1, i64 -1>
|
|
|
|
ret <2 x i64> %div
|
|
|
|
; CHECK-LABEL: @test18(
|
|
|
|
; CHECK-NEXT: sub <2 x i64> zeroinitializer, %x
|
|
|
|
; CHECK-NEXT: ret <2 x i64>
|
|
|
|
}
|
2014-05-14 11:03:05 +08:00
|
|
|
|
|
|
|
define i32 @test19(i32 %x) {
|
|
|
|
%A = udiv i32 1, %x
|
|
|
|
ret i32 %A
|
|
|
|
; CHECK-LABEL: @test19(
|
|
|
|
; CHECK-NEXT: icmp eq i32 %x, 1
|
|
|
|
; CHECK-NEXT: zext i1 %{{.*}} to i32
|
2015-08-11 03:01:27 +08:00
|
|
|
; CHECK-NEXT: ret i32
|
2014-05-14 11:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test20(i32 %x) {
|
|
|
|
%A = sdiv i32 1, %x
|
|
|
|
ret i32 %A
|
|
|
|
; CHECK-LABEL: @test20(
|
|
|
|
; CHECK-NEXT: add i32 %x, 1
|
|
|
|
; CHECK-NEXT: icmp ult i32 %{{.*}}, 3
|
|
|
|
; CHECK-NEXT: select i1 %{{.*}}, i32 %x, i32 {{.*}}
|
|
|
|
; CHECK-NEXT: ret i32
|
|
|
|
}
|
InstCombine: Combine mul with div.
We can combne a mul with a div if one of the operands is a multiple of
the other:
%mul = mul nsw nuw %a, C1
%ret = udiv %mul, C2
=>
%ret = mul nsw %a, (C1 / C2)
This can expose further optimization opportunities if we end up
multiplying or dividing by a power of 2.
Consider this small example:
define i32 @f(i32 %a) {
%mul = mul nuw i32 %a, 14
%div = udiv exact i32 %mul, 7
ret i32 %div
}
which gets CodeGen'd to:
imull $14, %edi, %eax
imulq $613566757, %rax, %rcx
shrq $32, %rcx
subl %ecx, %eax
shrl %eax
addl %ecx, %eax
shrl $2, %eax
retq
We can now transform this into:
define i32 @f(i32 %a) {
%shl = shl nuw i32 %a, 1
ret i32 %shl
}
which gets CodeGen'd to:
leal (%rdi,%rdi), %eax
retq
This fixes PR20681.
llvm-svn: 215815
2014-08-16 16:55:06 +08:00
|
|
|
|
|
|
|
define i32 @test21(i32 %a) {
|
|
|
|
%shl = shl nsw i32 %a, 2
|
|
|
|
%div = sdiv i32 %shl, 12
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test21(
|
|
|
|
; CHECK-NEXT: %div = sdiv i32 %a, 3
|
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test22(i32 %a) {
|
|
|
|
%mul = mul nsw i32 %a, 3
|
|
|
|
%div = sdiv i32 %mul, 12
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test22(
|
|
|
|
; CHECK-NEXT: %div = sdiv i32 %a, 4
|
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test23(i32 %a) {
|
|
|
|
%shl = shl nuw i32 %a, 2
|
|
|
|
%div = udiv i32 %shl, 12
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test23(
|
|
|
|
; CHECK-NEXT: %div = udiv i32 %a, 3
|
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test24(i32 %a) {
|
|
|
|
%mul = mul nuw i32 %a, 3
|
|
|
|
%div = udiv i32 %mul, 12
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test24(
|
|
|
|
; CHECK-NEXT: %div = lshr i32 %a, 2
|
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test25(i32 %a) {
|
|
|
|
%shl = shl nsw i32 %a, 2
|
|
|
|
%div = sdiv i32 %shl, 2
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test25(
|
2014-11-22 12:52:55 +08:00
|
|
|
; CHECK-NEXT: %div = shl nsw i32 %a, 1
|
InstCombine: Combine mul with div.
We can combne a mul with a div if one of the operands is a multiple of
the other:
%mul = mul nsw nuw %a, C1
%ret = udiv %mul, C2
=>
%ret = mul nsw %a, (C1 / C2)
This can expose further optimization opportunities if we end up
multiplying or dividing by a power of 2.
Consider this small example:
define i32 @f(i32 %a) {
%mul = mul nuw i32 %a, 14
%div = udiv exact i32 %mul, 7
ret i32 %div
}
which gets CodeGen'd to:
imull $14, %edi, %eax
imulq $613566757, %rax, %rcx
shrq $32, %rcx
subl %ecx, %eax
shrl %eax
addl %ecx, %eax
shrl $2, %eax
retq
We can now transform this into:
define i32 @f(i32 %a) {
%shl = shl nuw i32 %a, 1
ret i32 %shl
}
which gets CodeGen'd to:
leal (%rdi,%rdi), %eax
retq
This fixes PR20681.
llvm-svn: 215815
2014-08-16 16:55:06 +08:00
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test26(i32 %a) {
|
|
|
|
%mul = mul nsw i32 %a, 12
|
|
|
|
%div = sdiv i32 %mul, 3
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test26(
|
2014-11-22 12:52:55 +08:00
|
|
|
; CHECK-NEXT: %div = shl nsw i32 %a, 2
|
InstCombine: Combine mul with div.
We can combne a mul with a div if one of the operands is a multiple of
the other:
%mul = mul nsw nuw %a, C1
%ret = udiv %mul, C2
=>
%ret = mul nsw %a, (C1 / C2)
This can expose further optimization opportunities if we end up
multiplying or dividing by a power of 2.
Consider this small example:
define i32 @f(i32 %a) {
%mul = mul nuw i32 %a, 14
%div = udiv exact i32 %mul, 7
ret i32 %div
}
which gets CodeGen'd to:
imull $14, %edi, %eax
imulq $613566757, %rax, %rcx
shrq $32, %rcx
subl %ecx, %eax
shrl %eax
addl %ecx, %eax
shrl $2, %eax
retq
We can now transform this into:
define i32 @f(i32 %a) {
%shl = shl nuw i32 %a, 1
ret i32 %shl
}
which gets CodeGen'd to:
leal (%rdi,%rdi), %eax
retq
This fixes PR20681.
llvm-svn: 215815
2014-08-16 16:55:06 +08:00
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test27(i32 %a) {
|
|
|
|
%shl = shl nuw i32 %a, 2
|
|
|
|
%div = udiv i32 %shl, 2
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test27(
|
|
|
|
; CHECK-NEXT: %div = shl nuw i32 %a, 1
|
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test28(i32 %a) {
|
|
|
|
%mul = mul nuw i32 %a, 36
|
|
|
|
%div = udiv i32 %mul, 3
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test28(
|
|
|
|
; CHECK-NEXT: %div = mul nuw i32 %a, 12
|
|
|
|
; CHECK-NEXT: ret i32 %div
|
|
|
|
}
|
2014-10-11 18:20:04 +08:00
|
|
|
|
|
|
|
define i32 @test29(i32 %a) {
|
|
|
|
%mul = shl nsw i32 %a, 31
|
|
|
|
%div = sdiv i32 %mul, -2147483648
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test29(
|
|
|
|
; CHECK-NEXT: %[[and:.*]] = and i32 %a, 1
|
|
|
|
; CHECK-NEXT: ret i32 %[[and]]
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test30(i32 %a) {
|
|
|
|
%mul = shl nuw i32 %a, 31
|
|
|
|
%div = udiv i32 %mul, -2147483648
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test30(
|
|
|
|
; CHECK-NEXT: ret i32 %a
|
|
|
|
}
|
2014-10-14 05:48:30 +08:00
|
|
|
|
2014-10-15 04:28:40 +08:00
|
|
|
define <2 x i32> @test31(<2 x i32> %x) {
|
2014-10-14 05:48:30 +08:00
|
|
|
%shr = lshr <2 x i32> %x, <i32 31, i32 31>
|
|
|
|
%div = udiv <2 x i32> %shr, <i32 2147483647, i32 2147483647>
|
|
|
|
ret <2 x i32> %div
|
|
|
|
; CHECK-LABEL: @test31(
|
Handle non-constant shifts in computeKnownBits, and use computeKnownBits for constant folding in InstCombine/Simplify
First, the motivation: LLVM currently does not realize that:
((2072 >> (L == 0)) >> 7) & 1 == 0
where L is some arbitrary value. Whether you right-shift 2072 by 7 or by 8, the
lowest-order bit is always zero. There are obviously several ways to go about
fixing this, but the generic solution pursued in this patch is to teach
computeKnownBits something about shifts by a non-constant amount. Previously,
we would give up completely on these. Instead, in cases where we know something
about the low-order bits of the shift-amount operand, we can combine (and
together) the associated restrictions for all shift amounts consistent with
that knowledge. As a further generalization, I refactored all of the logic for
all three kinds of shifts to have this capability. This works well in the above
case, for example, because the dynamic shift amount can only be 0 or 1, and
thus we can say a lot about the known bits of the result.
This brings us to the second part of this change: Even when we know all of the
bits of a value via computeKnownBits, nothing used to constant-fold the result.
This introduces the necessary code into InstCombine and InstSimplify. I've
added it into both because:
1. InstCombine won't automatically pick up the associated logic in
InstSimplify (InstCombine uses InstSimplify, but not via the API that
passes in the original instruction).
2. Putting the logic in InstCombine allows the resulting simplifications to become
part of the iterative worklist
3. Putting the logic in InstSimplify allows the resulting simplifications to be
used by everywhere else that calls SimplifyInstruction (inlining, unrolling,
and many others).
And this requires a small change to our definition of an ephemeral value so
that we don't break the rest case from r246696 (where the icmp feeding the
@llvm.assume, is also feeding a br). Under the old definition, the icmp would
not be considered ephemeral (because it is used by the br), but this causes the
assume to remove itself (in addition to simplifying the branch structure), and
it seems more-useful to prevent that from happening.
llvm-svn: 251146
2015-10-24 04:37:08 +08:00
|
|
|
; CHECK-NEXT: ret <2 x i32> zeroinitializer
|
2014-10-14 05:48:30 +08:00
|
|
|
}
|
2014-10-15 04:28:40 +08:00
|
|
|
|
|
|
|
define i32 @test32(i32 %a, i32 %b) {
|
|
|
|
%shl = shl i32 2, %b
|
|
|
|
%div = lshr i32 %shl, 2
|
|
|
|
%div2 = udiv i32 %a, %div
|
|
|
|
ret i32 %div2
|
|
|
|
; CHECK-LABEL: @test32(
|
|
|
|
; CHECK-NEXT: %[[shl:.*]] = shl i32 2, %b
|
|
|
|
; CHECK-NEXT: %[[shr:.*]] = lshr i32 %[[shl]], 2
|
|
|
|
; CHECK-NEXT: %[[div:.*]] = udiv i32 %a, %[[shr]]
|
|
|
|
; CHECK-NEXT: ret i32
|
|
|
|
}
|
2014-11-23 02:16:54 +08:00
|
|
|
|
|
|
|
define <2 x i64> @test33(<2 x i64> %x) nounwind {
|
|
|
|
%shr = lshr exact <2 x i64> %x, <i64 5, i64 5>
|
|
|
|
%div = udiv exact <2 x i64> %shr, <i64 6, i64 6>
|
|
|
|
ret <2 x i64> %div
|
|
|
|
; CHECK-LABEL: @test33(
|
|
|
|
; CHECK-NEXT: udiv exact <2 x i64> %x, <i64 192, i64 192>
|
|
|
|
; CHECK-NEXT: ret <2 x i64>
|
|
|
|
}
|
2014-11-23 04:00:34 +08:00
|
|
|
|
|
|
|
define <2 x i64> @test34(<2 x i64> %x) nounwind {
|
|
|
|
%neg = sub nsw <2 x i64> zeroinitializer, %x
|
|
|
|
%div = sdiv exact <2 x i64> %neg, <i64 3, i64 4>
|
|
|
|
ret <2 x i64> %div
|
|
|
|
; CHECK-LABEL: @test34(
|
|
|
|
; CHECK-NEXT: sdiv exact <2 x i64> %x, <i64 -3, i64 -4>
|
|
|
|
; CHECK-NEXT: ret <2 x i64>
|
|
|
|
}
|
2014-11-23 04:00:38 +08:00
|
|
|
|
|
|
|
define i32 @test35(i32 %A) {
|
|
|
|
%and = and i32 %A, 2147483647
|
|
|
|
%mul = sdiv exact i32 %and, 2147483647
|
|
|
|
ret i32 %mul
|
|
|
|
; CHECK-LABEL: @test35(
|
|
|
|
; CHECK-NEXT: %[[and:.*]] = and i32 %A, 2147483647
|
|
|
|
; CHECK-NEXT: %[[udiv:.*]] = udiv exact i32 %[[and]], 2147483647
|
|
|
|
; CHECK-NEXT: ret i32 %[[udiv]]
|
|
|
|
}
|
2014-11-23 04:00:41 +08:00
|
|
|
|
|
|
|
define i32 @test36(i32 %A) {
|
|
|
|
%and = and i32 %A, 2147483647
|
|
|
|
%shl = shl nsw i32 1, %A
|
|
|
|
%mul = sdiv exact i32 %and, %shl
|
|
|
|
ret i32 %mul
|
|
|
|
; CHECK-LABEL: @test36(
|
|
|
|
; CHECK-NEXT: %[[and:.*]] = and i32 %A, 2147483647
|
|
|
|
; CHECK-NEXT: %[[shr:.*]] = lshr exact i32 %[[and]], %A
|
|
|
|
; CHECK-NEXT: ret i32 %[[shr]]
|
|
|
|
}
|
2015-09-06 14:49:59 +08:00
|
|
|
|
|
|
|
define i32 @test37(i32* %b) {
|
|
|
|
entry:
|
|
|
|
store i32 0, i32* %b, align 4
|
|
|
|
%0 = load i32, i32* %b, align 4
|
|
|
|
br i1 undef, label %lor.rhs, label %lor.end
|
|
|
|
|
|
|
|
lor.rhs: ; preds = %entry
|
|
|
|
%mul = mul nsw i32 undef, %0
|
|
|
|
br label %lor.end
|
|
|
|
|
|
|
|
lor.end: ; preds = %lor.rhs, %entry
|
|
|
|
%t.0 = phi i32 [ %0, %entry ], [ %mul, %lor.rhs ]
|
|
|
|
%div = sdiv i32 %t.0, 2
|
|
|
|
ret i32 %div
|
|
|
|
; CHECK-LABEL: @test37(
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|