2009-09-11 18:01:28 +00:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2009-08-11 20:47:47 +00:00
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv1(
|
2009-08-11 20:47:47 +00:00
|
|
|
; CHECK: sdiv i32 %x, 8
|
2011-02-10 05:23:05 +00:00
|
|
|
define i32 @sdiv1(i32 %x) {
|
2009-08-11 20:47:47 +00:00
|
|
|
%y = sdiv i32 %x, 8
|
|
|
|
ret i32 %y
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv2(
|
2011-02-10 05:36:31 +00:00
|
|
|
; CHECK: ashr exact i32 %x, 3
|
|
|
|
define i32 @sdiv2(i32 %x) {
|
|
|
|
%y = sdiv exact i32 %x, 8
|
|
|
|
ret i32 %y
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv3(
|
2009-08-12 16:33:09 +00:00
|
|
|
; CHECK: %y = srem i32 %x, 3
|
|
|
|
; CHECK: %z = sub i32 %x, %y
|
|
|
|
; CHECK: ret i32 %z
|
2011-02-10 05:23:05 +00:00
|
|
|
define i32 @sdiv3(i32 %x) {
|
2009-08-12 16:33:09 +00:00
|
|
|
%y = sdiv i32 %x, 3
|
|
|
|
%z = mul i32 %y, 3
|
|
|
|
ret i32 %z
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv4(
|
2009-08-12 16:33:09 +00:00
|
|
|
; CHECK: ret i32 %x
|
2011-02-10 05:23:05 +00:00
|
|
|
define i32 @sdiv4(i32 %x) {
|
2009-08-12 16:33:09 +00:00
|
|
|
%y = sdiv exact i32 %x, 3
|
|
|
|
%z = mul i32 %y, 3
|
|
|
|
ret i32 %z
|
|
|
|
}
|
|
|
|
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: i32 @sdiv5
|
2009-08-12 16:33:09 +00:00
|
|
|
; CHECK: %y = srem i32 %x, 3
|
|
|
|
; CHECK: %z = sub i32 %y, %x
|
|
|
|
; CHECK: ret i32 %z
|
2011-02-10 05:23:05 +00:00
|
|
|
define i32 @sdiv5(i32 %x) {
|
2009-08-12 16:33:09 +00:00
|
|
|
%y = sdiv i32 %x, 3
|
|
|
|
%z = mul i32 %y, -3
|
|
|
|
ret i32 %z
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv6(
|
2009-08-12 16:33:09 +00:00
|
|
|
; CHECK: %z = sub i32 0, %x
|
|
|
|
; CHECK: ret i32 %z
|
2011-02-10 05:23:05 +00:00
|
|
|
define i32 @sdiv6(i32 %x) {
|
2009-08-12 16:33:09 +00:00
|
|
|
%y = sdiv exact i32 %x, 3
|
|
|
|
%z = mul i32 %y, -3
|
|
|
|
ret i32 %z
|
|
|
|
}
|
2011-02-06 21:44:57 +00:00
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @udiv1(
|
2011-02-06 21:44:57 +00:00
|
|
|
; CHECK: ret i32 %x
|
2011-02-10 05:23:05 +00:00
|
|
|
define i32 @udiv1(i32 %x, i32 %w) {
|
2011-02-06 21:44:57 +00:00
|
|
|
%y = udiv exact i32 %x, %w
|
|
|
|
%z = mul i32 %y, %w
|
|
|
|
ret i32 %z
|
|
|
|
}
|
2011-02-10 05:23:05 +00:00
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @udiv2(
|
2011-02-10 05:36:31 +00:00
|
|
|
; CHECK: %z = lshr exact i32 %x, %w
|
|
|
|
; CHECK: ret i32 %z
|
|
|
|
define i32 @udiv2(i32 %x, i32 %w) {
|
|
|
|
%y = shl i32 1, %w
|
|
|
|
%z = udiv exact i32 %x, %y
|
|
|
|
ret i32 %z
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @ashr1(
|
2011-02-10 05:36:31 +00:00
|
|
|
; CHECK: %B = ashr exact i64 %A, 2
|
|
|
|
; CHECK: ret i64 %B
|
|
|
|
define i64 @ashr1(i64 %X) nounwind {
|
|
|
|
%A = shl i64 %X, 8
|
|
|
|
%B = ashr i64 %A, 2 ; X/4
|
|
|
|
ret i64 %B
|
|
|
|
}
|
|
|
|
|
2011-02-13 08:27:31 +00:00
|
|
|
; PR9120
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @ashr_icmp1(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: %B = icmp eq i64 %X, 0
|
|
|
|
; CHECK: ret i1 %B
|
2011-02-13 08:07:21 +00:00
|
|
|
define i1 @ashr_icmp1(i64 %X) nounwind {
|
2011-02-10 05:23:05 +00:00
|
|
|
%A = ashr exact i64 %X, 2 ; X/4
|
|
|
|
%B = icmp eq i64 %A, 0
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @ashr_icmp2(
|
2011-02-13 08:07:21 +00:00
|
|
|
; CHECK: %Z = icmp slt i64 %X, 16
|
|
|
|
; CHECK: ret i1 %Z
|
|
|
|
define i1 @ashr_icmp2(i64 %X) nounwind {
|
|
|
|
%Y = ashr exact i64 %X, 2 ; x / 4
|
|
|
|
%Z = icmp slt i64 %Y, 4 ; x < 16
|
|
|
|
ret i1 %Z
|
|
|
|
}
|
|
|
|
|
2011-05-25 23:26:20 +00:00
|
|
|
; PR9998
|
|
|
|
; Make sure we don't transform the ashr here into an sdiv
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @pr9998(
|
2013-02-15 14:35:47 +00:00
|
|
|
; CHECK: [[BIT:%[A-Za-z0-9.]+]] = and i32 %V, 1
|
|
|
|
; CHECK-NEXT: [[CMP:%[A-Za-z0-9.]+]] = icmp ne i32 [[BIT]], 0
|
|
|
|
; CHECK-NEXT: ret i1 [[CMP]]
|
2011-05-25 23:26:20 +00:00
|
|
|
define i1 @pr9998(i32 %V) nounwind {
|
|
|
|
entry:
|
|
|
|
%W = shl i32 %V, 31
|
|
|
|
%X = ashr exact i32 %W, 31
|
|
|
|
%Y = sext i32 %X to i64
|
|
|
|
%Z = icmp ugt i64 %Y, 7297771788697658747
|
|
|
|
ret i1 %Z
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-15 14:35:47 +00:00
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @udiv_icmp1(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp ne i64 %X, 0
|
|
|
|
define i1 @udiv_icmp1(i64 %X) nounwind {
|
|
|
|
%A = udiv exact i64 %X, 5 ; X/5
|
|
|
|
%B = icmp ne i64 %A, 0
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv_icmp1(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp eq i64 %X, 0
|
|
|
|
define i1 @sdiv_icmp1(i64 %X) nounwind {
|
|
|
|
%A = sdiv exact i64 %X, 5 ; X/5 == 0 --> x == 0
|
|
|
|
%B = icmp eq i64 %A, 0
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv_icmp2(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp eq i64 %X, 5
|
|
|
|
define i1 @sdiv_icmp2(i64 %X) nounwind {
|
|
|
|
%A = sdiv exact i64 %X, 5 ; X/5 == 1 --> x == 5
|
|
|
|
%B = icmp eq i64 %A, 1
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv_icmp3(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp eq i64 %X, -5
|
|
|
|
define i1 @sdiv_icmp3(i64 %X) nounwind {
|
|
|
|
%A = sdiv exact i64 %X, 5 ; X/5 == -1 --> x == -5
|
|
|
|
%B = icmp eq i64 %A, -1
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv_icmp4(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp eq i64 %X, 0
|
|
|
|
define i1 @sdiv_icmp4(i64 %X) nounwind {
|
|
|
|
%A = sdiv exact i64 %X, -5 ; X/-5 == 0 --> x == 0
|
|
|
|
%B = icmp eq i64 %A, 0
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv_icmp5(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp eq i64 %X, -5
|
|
|
|
define i1 @sdiv_icmp5(i64 %X) nounwind {
|
|
|
|
%A = sdiv exact i64 %X, -5 ; X/-5 == 1 --> x == -5
|
|
|
|
%B = icmp eq i64 %A, 1
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @sdiv_icmp6(
|
2011-02-10 05:23:05 +00:00
|
|
|
; CHECK: icmp eq i64 %X, 5
|
|
|
|
define i1 @sdiv_icmp6(i64 %X) nounwind {
|
|
|
|
%A = sdiv exact i64 %X, -5 ; X/-5 == 1 --> x == 5
|
|
|
|
%B = icmp eq i64 %A, -1
|
|
|
|
ret i1 %B
|
|
|
|
}
|
|
|
|
|