2011-01-29 00:51:11 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2008-11-21 15:33:58 +08:00
|
|
|
; PR3103
|
|
|
|
|
|
|
|
define i8 @test1(i8 %x, i8 %y) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test1(
|
2008-11-21 15:33:58 +08:00
|
|
|
%A = udiv i8 %x, %y
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: urem
|
2008-11-21 15:33:58 +08:00
|
|
|
%B = mul i8 %A, %y
|
|
|
|
%C = sub i8 %x, %B
|
|
|
|
ret i8 %C
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 15:33:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test2(i8 %x, i8 %y) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
2008-11-21 15:33:58 +08:00
|
|
|
%A = sdiv i8 %x, %y
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: srem
|
2008-11-21 15:33:58 +08:00
|
|
|
%B = mul i8 %A, %y
|
|
|
|
%C = sub i8 %x, %B
|
|
|
|
ret i8 %C
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 15:33:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test3(i8 %x, i8 %y) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test3(
|
2008-11-21 15:33:58 +08:00
|
|
|
%A = udiv i8 %x, %y
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: urem
|
2008-11-21 15:33:58 +08:00
|
|
|
%B = mul i8 %A, %y
|
|
|
|
%C = sub i8 %B, %x
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: sub
|
2008-11-21 15:33:58 +08:00
|
|
|
ret i8 %C
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 15:33:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test4(i8 %x) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test4(
|
2008-11-21 15:33:58 +08:00
|
|
|
%A = udiv i8 %x, 3
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: urem
|
2008-11-21 15:33:58 +08:00
|
|
|
%B = mul i8 %A, -3
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: sub
|
2008-11-21 15:33:58 +08:00
|
|
|
%C = sub i8 %x, %B
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: add
|
2008-11-21 15:33:58 +08:00
|
|
|
ret i8 %C
|
2011-01-29 00:51:11 +08:00
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test5(i32 %x, i32 %y) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test5(
|
2011-01-29 00:51:11 +08:00
|
|
|
; (((X / Y) * Y) / Y) -> X / Y
|
|
|
|
%div = sdiv i32 %x, %y
|
|
|
|
; CHECK-NEXT: sdiv
|
|
|
|
%mul = mul i32 %div, %y
|
|
|
|
%r = sdiv i32 %mul, %y
|
|
|
|
ret i32 %r
|
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test6(i32 %x, i32 %y) {
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @test6(
|
2011-01-29 00:51:11 +08:00
|
|
|
; (((X / Y) * Y) / Y) -> X / Y
|
|
|
|
%div = udiv i32 %x, %y
|
|
|
|
; CHECK-NEXT: udiv
|
|
|
|
%mul = mul i32 %div, %y
|
|
|
|
%r = udiv i32 %mul, %y
|
|
|
|
ret i32 %r
|
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 15:33:58 +08:00
|
|
|
}
|