2013-01-01 14:57:25 +01:00
|
|
|
; RUN: opt -instcombine -S < %s | FileCheck %s
|
2009-11-09 08:07:56 +01:00
|
|
|
|
2009-11-29 03:57:29 +01:00
|
|
|
%overflow.result = type {i8, i1}
|
|
|
|
|
|
|
|
declare %overflow.result @llvm.uadd.with.overflow.i8(i8, i8)
|
|
|
|
declare %overflow.result @llvm.umul.with.overflow.i8(i8, i8)
|
2010-01-01 02:52:15 +01:00
|
|
|
declare double @llvm.powi.f64(double, i32) nounwind readonly
|
2011-12-12 12:59:10 +01:00
|
|
|
declare i32 @llvm.cttz.i32(i32, i1) nounwind readnone
|
|
|
|
declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
|
2010-01-05 19:09:56 +01:00
|
|
|
declare i32 @llvm.ctpop.i32(i32) nounwind readnone
|
2011-12-12 12:59:10 +01:00
|
|
|
declare i8 @llvm.ctlz.i8(i8, i1) nounwind readnone
|
2009-11-09 08:07:56 +01:00
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @uaddtest1(i8 %A, i8 %B) {
|
2009-11-29 03:57:29 +01:00
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 %B)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
2009-11-09 08:07:56 +01:00
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest1(
|
2009-11-09 08:07:56 +01:00
|
|
|
; CHECK-NEXT: %y = add i8 %A, %B
|
|
|
|
; CHECK-NEXT: ret i8 %y
|
|
|
|
}
|
2009-11-29 03:57:29 +01:00
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @uaddtest2(i8 %A, i8 %B, i1* %overflowPtr) {
|
2009-11-29 03:57:29 +01:00
|
|
|
%and.A = and i8 %A, 127
|
|
|
|
%and.B = and i8 %B, 127
|
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %and.A, i8 %and.B)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
store i1 %z, i1* %overflowPtr
|
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest2(
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: %and.A = and i8 %A, 127
|
|
|
|
; CHECK-NEXT: %and.B = and i8 %B, 127
|
2011-05-18 21:57:14 +02:00
|
|
|
; CHECK-NEXT: %x = add nuw i8 %and.A, %and.B
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: store i1 false, i1* %overflowPtr
|
2011-05-18 21:57:14 +02:00
|
|
|
; CHECK-NEXT: ret i8 %x
|
2009-11-29 03:57:29 +01:00
|
|
|
}
|
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @uaddtest3(i8 %A, i8 %B, i1* %overflowPtr) {
|
2009-11-29 03:57:29 +01:00
|
|
|
%or.A = or i8 %A, -128
|
|
|
|
%or.B = or i8 %B, -128
|
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %or.A, i8 %or.B)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
store i1 %z, i1* %overflowPtr
|
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest3(
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: %or.A = or i8 %A, -128
|
|
|
|
; CHECK-NEXT: %or.B = or i8 %B, -128
|
2011-05-18 21:57:14 +02:00
|
|
|
; CHECK-NEXT: %x = add i8 %or.A, %or.B
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: store i1 true, i1* %overflowPtr
|
2011-05-18 21:57:14 +02:00
|
|
|
; CHECK-NEXT: ret i8 %x
|
2009-11-29 03:57:29 +01:00
|
|
|
}
|
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @uaddtest4(i8 %A, i1* %overflowPtr) {
|
2009-11-29 03:57:29 +01:00
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 undef, i8 %A)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
store i1 %z, i1* %overflowPtr
|
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest4(
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: ret i8 undef
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @uaddtest5(i8 %A, i1* %overflowPtr) {
|
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 0, i8 %A)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
store i1 %z, i1* %overflowPtr
|
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest5(
|
2010-08-09 22:49:43 +02:00
|
|
|
; CHECK: ret i8 %A
|
|
|
|
}
|
|
|
|
|
2010-12-19 20:35:32 +01:00
|
|
|
define i1 @uaddtest6(i8 %A, i8 %B) {
|
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 -4)
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
ret i1 %z
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest6(
|
2010-12-19 20:35:32 +01:00
|
|
|
; CHECK-NEXT: %z = icmp ugt i8 %A, 3
|
|
|
|
; CHECK-NEXT: ret i1 %z
|
|
|
|
}
|
|
|
|
|
X86 supports i8/i16 overflow ops (except i8 multiplies), we should
generate them.
Now we compile:
define zeroext i8 @X(i8 signext %a, i8 signext %b) nounwind ssp {
entry:
%0 = tail call %0 @llvm.sadd.with.overflow.i8(i8 %a, i8 %b)
%cmp = extractvalue %0 %0, 1
br i1 %cmp, label %if.then, label %if.end
into:
_X: ## @X
## BB#0: ## %entry
subl $12, %esp
movb 16(%esp), %al
addb 20(%esp), %al
jo LBB0_2
Before we were generating:
_X: ## @X
## BB#0: ## %entry
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movb 12(%ebp), %al
testb %al, %al
setge %cl
movb 8(%ebp), %dl
testb %dl, %dl
setge %ah
cmpb %cl, %ah
sete %cl
addb %al, %dl
testb %dl, %dl
setge %al
cmpb %al, %ah
setne %al
andb %cl, %al
testb %al, %al
jne LBB0_2
llvm-svn: 122186
2010-12-19 21:03:11 +01:00
|
|
|
define i8 @uaddtest7(i8 %A, i8 %B) {
|
|
|
|
%x = call %overflow.result @llvm.uadd.with.overflow.i8(i8 %A, i8 %B)
|
|
|
|
%z = extractvalue %overflow.result %x, 0
|
|
|
|
ret i8 %z
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @uaddtest7(
|
X86 supports i8/i16 overflow ops (except i8 multiplies), we should
generate them.
Now we compile:
define zeroext i8 @X(i8 signext %a, i8 signext %b) nounwind ssp {
entry:
%0 = tail call %0 @llvm.sadd.with.overflow.i8(i8 %a, i8 %b)
%cmp = extractvalue %0 %0, 1
br i1 %cmp, label %if.then, label %if.end
into:
_X: ## @X
## BB#0: ## %entry
subl $12, %esp
movb 16(%esp), %al
addb 20(%esp), %al
jo LBB0_2
Before we were generating:
_X: ## @X
## BB#0: ## %entry
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movb 12(%ebp), %al
testb %al, %al
setge %cl
movb 8(%ebp), %dl
testb %dl, %dl
setge %ah
cmpb %cl, %ah
sete %cl
addb %al, %dl
testb %dl, %dl
setge %al
cmpb %al, %ah
setne %al
andb %cl, %al
testb %al, %al
jne LBB0_2
llvm-svn: 122186
2010-12-19 21:03:11 +01:00
|
|
|
; CHECK-NEXT: %z = add i8 %A, %B
|
|
|
|
; CHECK-NEXT: ret i8 %z
|
|
|
|
}
|
|
|
|
|
2010-12-19 20:35:32 +01:00
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @umultest1(i8 %A, i1* %overflowPtr) {
|
2009-11-29 03:57:29 +01:00
|
|
|
%x = call %overflow.result @llvm.umul.with.overflow.i8(i8 0, i8 %A)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
store i1 %z, i1* %overflowPtr
|
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @umultest1(
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: store i1 false, i1* %overflowPtr
|
|
|
|
; CHECK-NEXT: ret i8 0
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:49:43 +02:00
|
|
|
define i8 @umultest2(i8 %A, i1* %overflowPtr) {
|
2009-11-29 03:57:29 +01:00
|
|
|
%x = call %overflow.result @llvm.umul.with.overflow.i8(i8 1, i8 %A)
|
|
|
|
%y = extractvalue %overflow.result %x, 0
|
|
|
|
%z = extractvalue %overflow.result %x, 1
|
|
|
|
store i1 %z, i1* %overflowPtr
|
|
|
|
ret i8 %y
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @umultest2(
|
2009-11-29 03:57:29 +01:00
|
|
|
; CHECK-NEXT: store i1 false, i1* %overflowPtr
|
|
|
|
; CHECK-NEXT: ret i8 %A
|
|
|
|
}
|
2010-01-01 02:52:15 +01:00
|
|
|
|
2011-03-10 19:40:14 +01:00
|
|
|
%ov.result.32 = type { i32, i1 }
|
|
|
|
declare %ov.result.32 @llvm.umul.with.overflow.i32(i32, i32) nounwind readnone
|
|
|
|
|
|
|
|
define i32 @umultest3(i32 %n) nounwind {
|
|
|
|
%shr = lshr i32 %n, 2
|
|
|
|
%mul = call %ov.result.32 @llvm.umul.with.overflow.i32(i32 %shr, i32 3)
|
|
|
|
%ov = extractvalue %ov.result.32 %mul, 1
|
|
|
|
%res = extractvalue %ov.result.32 %mul, 0
|
|
|
|
%ret = select i1 %ov, i32 -1, i32 %res
|
|
|
|
ret i32 %ret
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @umultest3(
|
2011-03-10 19:40:14 +01:00
|
|
|
; CHECK-NEXT: shr
|
|
|
|
; CHECK-NEXT: mul nuw
|
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @umultest4(i32 %n) nounwind {
|
|
|
|
%shr = lshr i32 %n, 1
|
|
|
|
%mul = call %ov.result.32 @llvm.umul.with.overflow.i32(i32 %shr, i32 4)
|
|
|
|
%ov = extractvalue %ov.result.32 %mul, 1
|
|
|
|
%res = extractvalue %ov.result.32 %mul, 0
|
|
|
|
%ret = select i1 %ov, i32 -1, i32 %res
|
|
|
|
ret i32 %ret
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @umultest4(
|
2011-03-10 19:40:14 +01:00
|
|
|
; CHECK: umul.with.overflow
|
|
|
|
}
|
|
|
|
|
2010-01-01 02:52:15 +01:00
|
|
|
define void @powi(double %V, double *%P) {
|
|
|
|
entry:
|
|
|
|
%A = tail call double @llvm.powi.f64(double %V, i32 -1) nounwind
|
2011-11-27 07:54:59 +01:00
|
|
|
store volatile double %A, double* %P
|
2010-01-01 02:52:15 +01:00
|
|
|
|
|
|
|
%B = tail call double @llvm.powi.f64(double %V, i32 0) nounwind
|
2011-11-27 07:54:59 +01:00
|
|
|
store volatile double %B, double* %P
|
2010-01-01 02:52:15 +01:00
|
|
|
|
|
|
|
%C = tail call double @llvm.powi.f64(double %V, i32 1) nounwind
|
2011-11-27 07:54:59 +01:00
|
|
|
store volatile double %C, double* %P
|
2010-01-01 02:52:15 +01:00
|
|
|
ret void
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @powi(
|
2010-01-01 02:52:15 +01:00
|
|
|
; CHECK: %A = fdiv double 1.0{{.*}}, %V
|
2013-02-08 02:55:39 +01:00
|
|
|
; CHECK: store volatile double %A,
|
|
|
|
; CHECK: store volatile double 1.0
|
2011-08-13 00:50:01 +02:00
|
|
|
; CHECK: store volatile double %V
|
2010-01-01 02:52:15 +01:00
|
|
|
}
|
|
|
|
|
2010-01-05 19:09:56 +01:00
|
|
|
define i32 @cttz(i32 %a) {
|
2010-01-05 08:23:56 +01:00
|
|
|
entry:
|
|
|
|
%or = or i32 %a, 8
|
|
|
|
%and = and i32 %or, -8
|
2011-12-12 12:59:10 +01:00
|
|
|
%count = tail call i32 @llvm.cttz.i32(i32 %and, i1 true) nounwind readnone
|
2010-01-05 08:23:56 +01:00
|
|
|
ret i32 %count
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @cttz(
|
2010-01-05 08:23:56 +01:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: ret i32 3
|
|
|
|
}
|
2010-01-01 02:52:15 +01:00
|
|
|
|
2010-01-05 19:09:56 +01:00
|
|
|
define i8 @ctlz(i8 %a) {
|
2010-01-05 08:23:56 +01:00
|
|
|
entry:
|
|
|
|
%or = or i8 %a, 32
|
|
|
|
%and = and i8 %or, 63
|
2011-12-12 12:59:10 +01:00
|
|
|
%count = tail call i8 @llvm.ctlz.i8(i8 %and, i1 true) nounwind readnone
|
2010-01-05 08:23:56 +01:00
|
|
|
ret i8 %count
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @ctlz(
|
2010-01-05 08:23:56 +01:00
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: ret i8 2
|
|
|
|
}
|
2010-01-05 19:09:56 +01:00
|
|
|
|
|
|
|
define void @cmp.simplify(i32 %a, i32 %b, i1* %c) {
|
|
|
|
entry:
|
2011-12-24 18:31:46 +01:00
|
|
|
%lz = tail call i32 @llvm.ctlz.i32(i32 %a, i1 false) nounwind readnone
|
2010-01-05 19:09:56 +01:00
|
|
|
%lz.cmp = icmp eq i32 %lz, 32
|
2011-11-27 07:54:59 +01:00
|
|
|
store volatile i1 %lz.cmp, i1* %c
|
2011-12-24 18:31:46 +01:00
|
|
|
%tz = tail call i32 @llvm.cttz.i32(i32 %a, i1 false) nounwind readnone
|
2010-01-05 19:09:56 +01:00
|
|
|
%tz.cmp = icmp ne i32 %tz, 32
|
2011-11-27 07:54:59 +01:00
|
|
|
store volatile i1 %tz.cmp, i1* %c
|
2010-01-05 19:09:56 +01:00
|
|
|
%pop = tail call i32 @llvm.ctpop.i32(i32 %b) nounwind readnone
|
|
|
|
%pop.cmp = icmp eq i32 %pop, 0
|
2011-11-27 07:54:59 +01:00
|
|
|
store volatile i1 %pop.cmp, i1* %c
|
2010-01-05 19:09:56 +01:00
|
|
|
ret void
|
|
|
|
; CHECK: @cmp.simplify
|
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: %lz.cmp = icmp eq i32 %a, 0
|
2011-08-13 00:50:01 +02:00
|
|
|
; CHECK-NEXT: store volatile i1 %lz.cmp, i1* %c
|
2010-01-05 19:09:56 +01:00
|
|
|
; CHECK-NEXT: %tz.cmp = icmp ne i32 %a, 0
|
2011-08-13 00:50:01 +02:00
|
|
|
; CHECK-NEXT: store volatile i1 %tz.cmp, i1* %c
|
2010-01-05 19:09:56 +01:00
|
|
|
; CHECK-NEXT: %pop.cmp = icmp eq i32 %b, 0
|
2011-08-13 00:50:01 +02:00
|
|
|
; CHECK-NEXT: store volatile i1 %pop.cmp, i1* %c
|
2010-01-05 19:09:56 +01:00
|
|
|
}
|
2010-01-23 19:49:30 +01:00
|
|
|
|
2011-12-24 23:34:15 +01:00
|
|
|
define i32 @cttz_simplify1a(i32 %x) nounwind readnone ssp {
|
|
|
|
%tmp1 = tail call i32 @llvm.ctlz.i32(i32 %x, i1 false)
|
|
|
|
%shr3 = lshr i32 %tmp1, 5
|
2010-01-23 19:49:30 +01:00
|
|
|
ret i32 %shr3
|
2011-12-24 23:34:15 +01:00
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @cttz_simplify1a(
|
2010-01-23 19:49:30 +01:00
|
|
|
; CHECK: icmp eq i32 %x, 0
|
2011-12-24 23:34:15 +01:00
|
|
|
; CHECK-NEXT: zext i1
|
2010-01-23 19:49:30 +01:00
|
|
|
; CHECK-NEXT: ret i32
|
|
|
|
}
|
|
|
|
|
2011-12-24 23:34:15 +01:00
|
|
|
define i32 @cttz_simplify1b(i32 %x) nounwind readnone ssp {
|
|
|
|
%tmp1 = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true)
|
|
|
|
%shr3 = lshr i32 %tmp1, 5
|
|
|
|
ret i32 %shr3
|
2010-01-23 19:49:30 +01:00
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @cttz_simplify1b(
|
2011-12-24 23:34:15 +01:00
|
|
|
; CHECK-NEXT: ret i32 0
|
|
|
|
}
|
2013-01-24 17:28:28 +01:00
|
|
|
|
|
|
|
define i32 @ctlz_undef(i32 %Value) nounwind {
|
|
|
|
%ctlz = call i32 @llvm.ctlz.i32(i32 0, i1 true)
|
|
|
|
ret i32 %ctlz
|
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @ctlz_undef(
|
2013-01-24 17:28:28 +01:00
|
|
|
; CHECK-NEXT: ret i32 undef
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @cttz_undef(i32 %Value) nounwind {
|
|
|
|
%cttz = call i32 @llvm.cttz.i32(i32 0, i1 true)
|
|
|
|
ret i32 %cttz
|
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @cttz_undef(
|
2013-01-24 17:28:28 +01:00
|
|
|
; CHECK-NEXT: ret i32 undef
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @ctlz_select(i32 %Value) nounwind {
|
|
|
|
%tobool = icmp ne i32 %Value, 0
|
|
|
|
%ctlz = call i32 @llvm.ctlz.i32(i32 %Value, i1 true)
|
|
|
|
%s = select i1 %tobool, i32 %ctlz, i32 32
|
|
|
|
ret i32 %s
|
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @ctlz_select(
|
2013-01-24 17:28:28 +01:00
|
|
|
; CHECK: select i1 %tobool, i32 %ctlz, i32 32
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @cttz_select(i32 %Value) nounwind {
|
|
|
|
%tobool = icmp ne i32 %Value, 0
|
|
|
|
%cttz = call i32 @llvm.cttz.i32(i32 %Value, i1 true)
|
|
|
|
%s = select i1 %tobool, i32 %cttz, i32 32
|
|
|
|
ret i32 %s
|
|
|
|
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @cttz_select(
|
2013-01-24 17:28:28 +01:00
|
|
|
; CHECK: select i1 %tobool, i32 %cttz, i32 32
|
|
|
|
}
|