2004-03-12 06:01:00 +00:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
2007-11-25 21:27:53 +00:00
|
|
|
; PR1822
|
2004-03-12 06:01:00 +00:00
|
|
|
|
2009-12-21 06:06:10 +00:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2004-03-12 06:01:00 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test1(i32 %A, i32 %B) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%C = select i1 false, i32 %A, i32 %B
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %C
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test1
|
|
|
|
; CHECK: ret i32 %B
|
2004-03-12 06:01:00 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test2(i32 %A, i32 %B) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%C = select i1 true, i32 %A, i32 %B
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %C
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test2
|
|
|
|
; CHECK: ret i32 %A
|
2004-03-12 06:01:00 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
|
|
|
|
define i32 @test3(i1 %C, i32 %I) {
|
|
|
|
; V = I
|
2009-12-21 05:53:13 +00:00
|
|
|
%V = select i1 %C, i32 %I, i32 %I
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test3
|
|
|
|
; CHECK: ret i32 %I
|
2004-03-30 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test4(i1 %C) {
|
|
|
|
; V = C
|
2009-12-21 05:53:13 +00:00
|
|
|
%V = select i1 %C, i1 true, i1 false
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test4
|
|
|
|
; CHECK: ret i1 %C
|
2004-03-30 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test5(i1 %C) {
|
|
|
|
; V = !C
|
2009-12-21 05:53:13 +00:00
|
|
|
%V = select i1 %C, i1 false, i1 true
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test5
|
|
|
|
; CHECK: xor i1 %C, true
|
|
|
|
; CHECK: ret i1
|
2004-03-30 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test6(i1 %C) {
|
|
|
|
; V = cast C to int
|
2009-12-21 05:53:13 +00:00
|
|
|
%V = select i1 %C, i32 1, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test6
|
|
|
|
; CHECK: %V = zext i1 %C to i32
|
|
|
|
; CHECK: ret i32 %V
|
2004-03-30 19:36:54 +00:00
|
|
|
}
|
2004-03-12 06:01:00 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test7(i1 %C, i1 %X) {
|
|
|
|
; R = or C, X
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = select i1 %C, i1 true, i1 %X
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test7
|
|
|
|
; CHECK: %R = or i1 %C, %X
|
|
|
|
; CHECK: ret i1 %R
|
2004-04-08 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test8(i1 %C, i1 %X) {
|
|
|
|
; R = and C, X
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = select i1 %C, i1 %X, i1 false
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test8
|
|
|
|
; CHECK: %R = and i1 %C, %X
|
|
|
|
; CHECK: ret i1 %R
|
2004-04-08 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test9(i1 %C, i1 %X) {
|
|
|
|
; R = and !C, X
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = select i1 %C, i1 false, i1 %X
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test9
|
|
|
|
; CHECK: xor i1 %C, true
|
|
|
|
; CHECK: %R = and i1
|
|
|
|
; CHECK: ret i1 %R
|
2004-04-08 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test10(i1 %C, i1 %X) {
|
|
|
|
; R = or !C, X
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = select i1 %C, i1 %X, i1 true
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test10
|
|
|
|
; CHECK: xor i1 %C, true
|
|
|
|
; CHECK: %R = or i1
|
|
|
|
; CHECK: ret i1 %R
|
2004-04-08 04:43:04 +00:00
|
|
|
}
|
2004-04-09 18:19:29 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test11(i32 %a) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%C = icmp eq i32 %a, 0
|
|
|
|
%R = select i1 %C, i32 0, i32 1
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test11
|
|
|
|
; CHECK: icmp ne i32 %a, 0
|
|
|
|
; CHECK: %R = zext i1
|
2009-12-21 06:06:10 +00:00
|
|
|
; CHECK: ret i32 %R
|
2004-04-09 18:19:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test12(i1 %cond, i32 %a) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%b = or i32 %a, 1
|
|
|
|
%c = select i1 %cond, i32 %b, i32 %a
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %c
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test12
|
|
|
|
; CHECK: %b = zext i1 %cond to i32
|
|
|
|
; CHECK: %c = or i32 %b, %a
|
|
|
|
; CHECK: ret i32 %c
|
2004-04-09 23:43:48 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test12a(i1 %cond, i32 %a) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%b = ashr i32 %a, 1
|
|
|
|
%c = select i1 %cond, i32 %b, i32 %a
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %c
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test12a
|
|
|
|
; CHECK: %b = zext i1 %cond to i32
|
|
|
|
; CHECK: %c = ashr i32 %a, %b
|
|
|
|
; CHECK: ret i32 %c
|
2004-04-09 23:43:48 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test12b(i1 %cond, i32 %a) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%b = ashr i32 %a, 1
|
|
|
|
%c = select i1 %cond, i32 %a, i32 %b
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %c
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test12b
|
|
|
|
; CHECK: zext i1 %cond to i32
|
|
|
|
; CHECK: %b = xor i32
|
|
|
|
; CHECK: %c = ashr i32 %a, %b
|
|
|
|
; CHECK: ret i32 %c
|
2004-04-09 23:43:48 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test13(i32 %a, i32 %b) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%C = icmp eq i32 %a, %b
|
|
|
|
%V = select i1 %C, i32 %a, i32 %b
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test13
|
|
|
|
; CHECK: ret i32 %b
|
2004-04-10 22:21:14 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test13a(i32 %a, i32 %b) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%C = icmp ne i32 %a, %b
|
|
|
|
%V = select i1 %C, i32 %a, i32 %b
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test13a
|
|
|
|
; CHECK: ret i32 %a
|
2004-04-10 22:21:14 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test13b(i32 %a, i32 %b) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%C = icmp eq i32 %a, %b
|
|
|
|
%V = select i1 %C, i32 %b, i32 %a
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test13b
|
|
|
|
; CHECK: ret i32 %a
|
2004-04-10 22:21:14 +00:00
|
|
|
}
|
2004-06-09 04:23:57 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test14a(i1 %C, i32 %X) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%V = select i1 %C, i32 %X, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
; (X < 1) | !C
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = icmp slt i32 %V, 1
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test14a
|
|
|
|
; CHECK: icmp slt i32 %X, 1
|
|
|
|
; CHECK: xor i1 %C, true
|
|
|
|
; CHECK: or i1
|
|
|
|
; CHECK: ret i1 %R
|
2004-06-09 04:23:57 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test14b(i1 %C, i32 %X) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%V = select i1 %C, i32 0, i32 %X
|
2008-03-01 09:15:35 +00:00
|
|
|
; (X < 1) | C
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = icmp slt i32 %V, 1
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %R
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test14b
|
|
|
|
; CHECK: icmp slt i32 %X, 1
|
|
|
|
; CHECK: or i1
|
|
|
|
; CHECK: ret i1 %R
|
2004-06-09 04:23:57 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
;; Code sequence for (X & 16) ? 16 : 0
|
|
|
|
define i32 @test15a(i32 %X) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%t1 = and i32 %X, 16
|
|
|
|
%t2 = icmp eq i32 %t1, 0
|
|
|
|
%t3 = select i1 %t2, i32 0, i32 16
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %t3
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test15a
|
|
|
|
; CHECK: %t1 = and i32 %X, 16
|
|
|
|
; CHECK: ret i32 %t1
|
2004-06-09 07:59:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
;; Code sequence for (X & 32) ? 0 : 24
|
|
|
|
define i32 @test15b(i32 %X) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%t1 = and i32 %X, 32
|
|
|
|
%t2 = icmp eq i32 %t1, 0
|
|
|
|
%t3 = select i1 %t2, i32 32, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %t3
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test15b
|
|
|
|
; CHECK: %t1 = and i32 %X, 32
|
|
|
|
; CHECK: xor i32 %t1, 32
|
|
|
|
; CHECK: ret i32
|
2004-06-09 07:59:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
;; Alternate code sequence for (X & 16) ? 16 : 0
|
|
|
|
define i32 @test15c(i32 %X) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%t1 = and i32 %X, 16
|
|
|
|
%t2 = icmp eq i32 %t1, 16
|
|
|
|
%t3 = select i1 %t2, i32 16, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %t3
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test15c
|
|
|
|
; CHECK: %t1 = and i32 %X, 16
|
|
|
|
; CHECK: ret i32 %t1
|
2004-06-09 07:59:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
;; Alternate code sequence for (X & 16) ? 16 : 0
|
|
|
|
define i32 @test15d(i32 %X) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%t1 = and i32 %X, 16
|
|
|
|
%t2 = icmp ne i32 %t1, 0
|
|
|
|
%t3 = select i1 %t2, i32 16, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %t3
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test15d
|
|
|
|
; CHECK: %t1 = and i32 %X, 16
|
|
|
|
; CHECK: ret i32 %t1
|
2004-06-09 07:59:40 +00:00
|
|
|
}
|
2004-09-23 15:45:20 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test16(i1 %C, i32* %P) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%P2 = select i1 %C, i32* %P, i32* null
|
|
|
|
%V = load i32* %P2
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test16
|
|
|
|
; CHECK-NEXT: %V = load i32* %P
|
|
|
|
; CHECK: ret i32 %V
|
2004-09-23 15:45:20 +00:00
|
|
|
}
|
2005-04-23 15:31:03 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test17(i32* %X, i1 %C) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = select i1 %C, i32* %X, i32* null
|
|
|
|
%RV = icmp eq i32* %R, null
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %RV
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test17
|
|
|
|
; CHECK: icmp eq i32* %X, null
|
|
|
|
; CHECK: xor i1 %C, true
|
|
|
|
; CHECK: %RV = or i1
|
|
|
|
; CHECK: ret i1 %RV
|
2005-04-23 15:31:03 +00:00
|
|
|
}
|
2006-09-09 20:26:04 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test18(i32 %X, i32 %Y, i1 %C) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%R = select i1 %C, i32 %X, i32 0
|
|
|
|
%V = sdiv i32 %Y, %R
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %V
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test18
|
|
|
|
; CHECK: %V = sdiv i32 %Y, %X
|
|
|
|
; CHECK: ret i32 %V
|
2006-09-09 20:26:04 +00:00
|
|
|
}
|
2006-09-19 06:16:46 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test19(i32 %x) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%tmp = icmp ugt i32 %x, 2147483647
|
|
|
|
%retval = select i1 %tmp, i32 -1, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %retval
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test19
|
|
|
|
; CHECK-NEXT: ashr i32 %x, 31
|
|
|
|
; CHECK-NEXT: ret i32
|
2006-09-19 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test20(i32 %x) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%tmp = icmp slt i32 %x, 0
|
|
|
|
%retval = select i1 %tmp, i32 -1, i32 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %retval
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test20
|
|
|
|
; CHECK-NEXT: ashr i32 %x, 31
|
|
|
|
; CHECK-NEXT: ret i32
|
2006-09-19 06:16:46 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i64 @test21(i32 %x) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%tmp = icmp slt i32 %x, 0
|
|
|
|
%retval = select i1 %tmp, i64 -1, i64 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i64 %retval
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test21
|
|
|
|
; CHECK-NEXT: ashr i32 %x, 31
|
|
|
|
; CHECK-NEXT: sext i32
|
|
|
|
; CHECK-NEXT: ret i64
|
2006-09-19 06:17:55 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i16 @test22(i32 %x) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%tmp = icmp slt i32 %x, 0
|
|
|
|
%retval = select i1 %tmp, i16 -1, i16 0
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i16 %retval
|
2009-12-21 06:06:10 +00:00
|
|
|
; CHECK: @test22
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK-NEXT: ashr i32 %x, 31
|
|
|
|
; CHECK-NEXT: trunc i32
|
|
|
|
; CHECK-NEXT: ret i16
|
2006-09-19 06:17:55 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test23(i1 %a, i1 %b) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%c = select i1 %a, i1 %b, i1 %a
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %c
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test23
|
|
|
|
; CHECK-NEXT: %c = and i1 %a, %b
|
|
|
|
; CHECK-NEXT: ret i1 %c
|
2007-11-25 21:27:53 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i1 @test24(i1 %a, i1 %b) {
|
2009-12-21 05:53:13 +00:00
|
|
|
%c = select i1 %a, i1 %a, i1 %b
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i1 %c
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test24
|
|
|
|
; CHECK-NEXT: %c = or i1 %a, %b
|
|
|
|
; CHECK-NEXT: ret i1 %c
|
2007-11-25 21:27:53 +00:00
|
|
|
}
|
2008-03-01 09:15:35 +00:00
|
|
|
|
2009-09-27 20:18:49 +00:00
|
|
|
define i32 @test25(i1 %c) {
|
2009-09-27 19:57:57 +00:00
|
|
|
entry:
|
2009-09-27 20:18:49 +00:00
|
|
|
br i1 %c, label %jump, label %ret
|
2009-09-27 19:57:57 +00:00
|
|
|
jump:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%a = phi i1 [true, %jump], [false, %entry]
|
|
|
|
%b = select i1 %a, i32 10, i32 20
|
|
|
|
ret i32 %b
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test25
|
|
|
|
; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
|
|
|
|
; CHECK-NEXT: ret i32 %a
|
2009-09-27 19:57:57 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 20:18:49 +00:00
|
|
|
define i32 @test26(i1 %cond) {
|
2009-09-27 19:57:57 +00:00
|
|
|
entry:
|
2009-09-27 20:18:49 +00:00
|
|
|
br i1 %cond, label %jump, label %ret
|
2009-09-27 19:57:57 +00:00
|
|
|
jump:
|
|
|
|
%c = or i1 false, false
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%a = phi i1 [true, %jump], [%c, %entry]
|
|
|
|
%b = select i1 %a, i32 10, i32 20
|
|
|
|
ret i32 %b
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test26
|
|
|
|
; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
|
|
|
|
; CHECK-NEXT: ret i32 %a
|
2009-09-27 19:57:57 +00:00
|
|
|
}
|
2009-09-27 20:18:49 +00:00
|
|
|
|
|
|
|
define i32 @test27(i1 %c, i32 %A, i32 %B) {
|
|
|
|
entry:
|
|
|
|
br i1 %c, label %jump, label %ret
|
|
|
|
jump:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%a = phi i1 [true, %jump], [false, %entry]
|
|
|
|
%b = select i1 %a, i32 %A, i32 %B
|
|
|
|
ret i32 %b
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test27
|
|
|
|
; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
|
|
|
|
; CHECK-NEXT: ret i32 %a
|
2009-09-27 20:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test28(i1 %cond, i32 %A, i32 %B) {
|
|
|
|
entry:
|
|
|
|
br i1 %cond, label %jump, label %ret
|
|
|
|
jump:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%c = phi i32 [%A, %jump], [%B, %entry]
|
|
|
|
%a = phi i1 [true, %jump], [false, %entry]
|
|
|
|
%b = select i1 %a, i32 %A, i32 %c
|
|
|
|
ret i32 %b
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: @test28
|
|
|
|
; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
|
|
|
|
; CHECK-NEXT: ret i32 %a
|
2009-09-27 20:18:49 +00:00
|
|
|
}
|
2009-09-28 06:49:44 +00:00
|
|
|
|
|
|
|
define i32 @test29(i1 %cond, i32 %A, i32 %B) {
|
|
|
|
entry:
|
|
|
|
br i1 %cond, label %jump, label %ret
|
|
|
|
jump:
|
|
|
|
br label %ret
|
|
|
|
ret:
|
|
|
|
%c = phi i32 [%A, %jump], [%B, %entry]
|
|
|
|
%a = phi i1 [true, %jump], [false, %entry]
|
|
|
|
br label %next
|
|
|
|
|
|
|
|
next:
|
|
|
|
%b = select i1 %a, i32 %A, i32 %c
|
|
|
|
ret i32 %b
|
2009-12-21 06:06:10 +00:00
|
|
|
; CHECK: @test29
|
2009-12-21 05:53:13 +00:00
|
|
|
; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
|
2009-12-21 06:06:10 +00:00
|
|
|
; CHECK: ret i32 %a
|
2009-09-28 06:49:44 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 06:03:05 +00:00
|
|
|
|
2009-12-21 06:08:50 +00:00
|
|
|
; SMAX(SMAX(x, y), x) -> SMAX(x, y)
|
2009-12-21 06:03:05 +00:00
|
|
|
define i32 @test30(i32 %x, i32 %y) {
|
|
|
|
%cmp = icmp sgt i32 %x, %y
|
|
|
|
%cond = select i1 %cmp, i32 %x, i32 %y
|
2009-12-21 06:08:50 +00:00
|
|
|
|
2009-12-21 06:03:05 +00:00
|
|
|
%cmp5 = icmp sgt i32 %cond, %x
|
|
|
|
%retval = select i1 %cmp5, i32 %cond, i32 %x
|
|
|
|
ret i32 %retval
|
2009-12-21 06:08:50 +00:00
|
|
|
; CHECK: @test30
|
|
|
|
; CHECK: ret i32 %cond
|
2009-12-21 06:03:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 06:08:50 +00:00
|
|
|
; UMAX(UMAX(x, y), x) -> UMAX(x, y)
|
2009-12-21 06:03:05 +00:00
|
|
|
define i32 @test31(i32 %x, i32 %y) {
|
|
|
|
%cmp = icmp ugt i32 %x, %y
|
|
|
|
%cond = select i1 %cmp, i32 %x, i32 %y
|
|
|
|
%cmp5 = icmp ugt i32 %cond, %x
|
|
|
|
%retval = select i1 %cmp5, i32 %cond, i32 %x
|
|
|
|
ret i32 %retval
|
2009-12-21 06:08:50 +00:00
|
|
|
; CHECK: @test31
|
|
|
|
; CHECK: ret i32 %cond
|
2009-12-21 06:03:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 06:08:50 +00:00
|
|
|
; SMIN(SMIN(x, y), x) -> SMIN(x, y)
|
2009-12-21 06:03:05 +00:00
|
|
|
define i32 @test32(i32 %x, i32 %y) {
|
|
|
|
%cmp = icmp sgt i32 %x, %y
|
|
|
|
%cond = select i1 %cmp, i32 %y, i32 %x
|
|
|
|
%cmp5 = icmp sgt i32 %cond, %x
|
|
|
|
%retval = select i1 %cmp5, i32 %x, i32 %cond
|
|
|
|
ret i32 %retval
|
2009-12-21 06:08:50 +00:00
|
|
|
; CHECK: @test32
|
|
|
|
; CHECK: ret i32 %cond
|
2009-12-21 06:03:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 06:08:50 +00:00
|
|
|
; MAX(MIN(x, y), x) -> x
|
2009-12-21 06:03:05 +00:00
|
|
|
define i32 @test33(i32 %x, i32 %y) {
|
|
|
|
%cmp = icmp sgt i32 %x, %y
|
|
|
|
%cond = select i1 %cmp, i32 %y, i32 %x
|
|
|
|
%cmp5 = icmp sgt i32 %cond, %x
|
|
|
|
%retval = select i1 %cmp5, i32 %cond, i32 %x
|
|
|
|
ret i32 %retval
|
2009-12-21 06:08:50 +00:00
|
|
|
; CHECK: @test33
|
|
|
|
; CHECK: ret i32 %x
|
2009-12-21 06:03:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 06:08:50 +00:00
|
|
|
; MIN(MAX(x, y), x) -> x
|
2009-12-21 06:03:05 +00:00
|
|
|
define i32 @test34(i32 %x, i32 %y) {
|
|
|
|
%cmp = icmp sgt i32 %x, %y
|
|
|
|
%cond = select i1 %cmp, i32 %x, i32 %y
|
|
|
|
%cmp5 = icmp sgt i32 %cond, %x
|
|
|
|
%retval = select i1 %cmp5, i32 %x, i32 %cond
|
|
|
|
ret i32 %retval
|
2009-12-21 06:08:50 +00:00
|
|
|
; CHECK: @test34
|
|
|
|
; CHECK: ret i32 %x
|
2009-12-21 06:03:05 +00:00
|
|
|
}
|
2010-07-08 11:39:10 +00:00
|
|
|
|
|
|
|
define i32 @test35(i32 %x) {
|
|
|
|
%cmp = icmp sge i32 %x, 0
|
|
|
|
%cond = select i1 %cmp, i32 60, i32 100
|
|
|
|
ret i32 %cond
|
|
|
|
; CHECK: @test35
|
|
|
|
; CHECK: ashr i32 %x, 31
|
|
|
|
; CHECK: and i32 {{.*}}, 40
|
|
|
|
; CHECK: add i32 {{.*}}, 60
|
|
|
|
; CHECK: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test36(i32 %x) {
|
|
|
|
%cmp = icmp slt i32 %x, 0
|
|
|
|
%cond = select i1 %cmp, i32 60, i32 100
|
|
|
|
ret i32 %cond
|
|
|
|
; CHECK: @test36
|
|
|
|
; CHECK: ashr i32 %x, 31
|
|
|
|
; CHECK: and i32 {{.*}}, -40
|
|
|
|
; CHECK: add i32 {{.*}}, 100
|
|
|
|
; CHECK: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test37(i32 %x) {
|
|
|
|
%cmp = icmp sgt i32 %x, -1
|
|
|
|
%cond = select i1 %cmp, i32 1, i32 -1
|
|
|
|
ret i32 %cond
|
|
|
|
; CHECK: @test37
|
|
|
|
; CHECK: ashr i32 %x, 31
|
|
|
|
; CHECK: or i32 {{.*}}, 1
|
|
|
|
; CHECK: ret
|
|
|
|
}
|
2010-11-07 16:12:23 +00:00
|
|
|
|
|
|
|
define i1 @test38(i1 %cond) {
|
|
|
|
%zero = alloca i32
|
|
|
|
%one = alloca i32
|
|
|
|
%ptr = select i1 %cond, i32* %zero, i32* %one
|
|
|
|
%isnull = icmp eq i32* %ptr, null
|
|
|
|
ret i1 %isnull
|
|
|
|
; CHECK: @test38
|
|
|
|
; CHECK: ret i1 false
|
|
|
|
}
|
2010-11-07 16:46:25 +00:00
|
|
|
|
|
|
|
define i1 @test39(i1 %cond, double %x) {
|
|
|
|
%s = select i1 %cond, double %x, double 0x7FF0000000000000 ; RHS = +infty
|
|
|
|
%cmp = fcmp ule double %x, %s
|
|
|
|
ret i1 %cmp
|
|
|
|
; CHECK: @test39
|
|
|
|
; CHECK: ret i1 true
|
|
|
|
}
|
2010-11-08 20:56:28 +00:00
|
|
|
|
|
|
|
define i1 @test40(i1 %cond) {
|
|
|
|
%a = alloca i32
|
|
|
|
%b = alloca i32
|
|
|
|
%c = alloca i32
|
|
|
|
%s = select i1 %cond, i32* %a, i32* %b
|
|
|
|
%r = icmp eq i32* %s, %c
|
|
|
|
ret i1 %r
|
|
|
|
; CHECK: @test40
|
|
|
|
; CHECK: ret i1 false
|
|
|
|
}
|
2010-11-10 18:23:01 +00:00
|
|
|
|
2010-11-15 16:43:28 +00:00
|
|
|
define i32 @test41(i1 %cond, i32 %x, i32 %y) {
|
2010-11-13 15:10:37 +00:00
|
|
|
%z = and i32 %x, %y
|
|
|
|
%s = select i1 %cond, i32 %y, i32 %z
|
|
|
|
%r = and i32 %x, %s
|
|
|
|
ret i32 %r
|
2010-11-15 16:43:28 +00:00
|
|
|
; CHECK: @test41
|
2010-11-13 15:10:37 +00:00
|
|
|
; CHECK: %r = and i32 %x, %y
|
|
|
|
; CHECK: ret i32 %r
|
|
|
|
}
|