2011-01-28 16:51:11 +00:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2008-11-21 07:33:58 +00:00
|
|
|
; PR3103
|
|
|
|
|
|
|
|
define i8 @test1(i8 %x, i8 %y) {
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK: @test1
|
2008-11-21 07:33:58 +00:00
|
|
|
%A = udiv i8 %x, %y
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: urem
|
2008-11-21 07:33:58 +00:00
|
|
|
%B = mul i8 %A, %y
|
|
|
|
%C = sub i8 %x, %B
|
|
|
|
ret i8 %C
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 07:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test2(i8 %x, i8 %y) {
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK: @test2
|
2008-11-21 07:33:58 +00:00
|
|
|
%A = sdiv i8 %x, %y
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: srem
|
2008-11-21 07:33:58 +00:00
|
|
|
%B = mul i8 %A, %y
|
|
|
|
%C = sub i8 %x, %B
|
|
|
|
ret i8 %C
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 07:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test3(i8 %x, i8 %y) {
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK: @test3
|
2008-11-21 07:33:58 +00:00
|
|
|
%A = udiv i8 %x, %y
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: urem
|
2008-11-21 07:33:58 +00:00
|
|
|
%B = mul i8 %A, %y
|
|
|
|
%C = sub i8 %B, %x
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: sub
|
2008-11-21 07:33:58 +00:00
|
|
|
ret i8 %C
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: ret
|
2008-11-21 07:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test4(i8 %x) {
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK: @test4
|
2008-11-21 07:33:58 +00:00
|
|
|
%A = udiv i8 %x, 3
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: urem
|
2008-11-21 07:33:58 +00:00
|
|
|
%B = mul i8 %A, -3
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: sub
|
2008-11-21 07:33:58 +00:00
|
|
|
%C = sub i8 %x, %B
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: add
|
2008-11-21 07:33:58 +00:00
|
|
|
ret i8 %C
|
2011-01-28 16:51:11 +00:00
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test5(i32 %x, i32 %y) {
|
|
|
|
; CHECK: @test5
|
|
|
|
; (((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) {
|
|
|
|
; CHECK: @test6
|
|
|
|
; (((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 07:33:58 +00:00
|
|
|
}
|