2002-05-06 13:43:36 +08:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
2009-10-26 07:47:55 +08:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2002-05-06 13:43:36 +08:00
|
|
|
|
2009-11-29 08:51:17 +08:00
|
|
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test1(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i32 %A, 0
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test1
|
|
|
|
; CHECK: ret i32 %A
|
2002-05-06 13:43:36 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test2(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i32 %A, -1
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test2
|
|
|
|
; CHECK: ret i32 -1
|
2002-05-06 13:43:36 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i8 @test2a(i8 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i8 %A, -1
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i8 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test2a
|
|
|
|
; CHECK: ret i8 -1
|
2003-03-11 06:43:56 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test3(i1 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i1 %A, false
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test3
|
|
|
|
; CHECK: ret i1 %A
|
2002-05-06 13:43:36 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test4(i1 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i1 %A, true
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test4
|
|
|
|
; CHECK: ret i1 true
|
2002-05-06 13:43:36 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test5(i1 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i1 %A, %A
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test5
|
|
|
|
; CHECK: ret i1 %A
|
2002-05-06 13:51:26 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test6(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i32 %A, %A
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test6
|
|
|
|
; CHECK: ret i32 %A
|
2002-05-06 13:51:26 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
; A | ~A == -1
|
|
|
|
define i32 @test7(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%NotA = xor i32 -1, %A
|
|
|
|
%B = or i32 %A, %NotA
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %B
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test7
|
|
|
|
; CHECK: ret i32 -1
|
2003-02-19 03:28:47 +08:00
|
|
|
}
|
2003-03-11 02:24:04 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i8 @test8(i8 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i8 %A, -2
|
|
|
|
%C = or i8 %B, 1
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i8 %C
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test8
|
|
|
|
; CHECK: ret i8 -1
|
2003-03-11 06:43:56 +08:00
|
|
|
}
|
2003-03-11 07:52:54 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
|
|
|
|
define i8 @test9(i8 %A, i8 %B) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%C = or i8 %A, 1
|
|
|
|
%D = or i8 %B, -2
|
|
|
|
%E = or i8 %C, %D
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i8 %E
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test9
|
|
|
|
; CHECK: ret i8 -1
|
2003-03-11 08:10:59 +08:00
|
|
|
}
|
2003-06-04 12:37:46 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i8 @test10(i8 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i8 %A, 1
|
|
|
|
%C = and i8 %B, -2
|
2008-03-01 17:15:35 +08:00
|
|
|
; (X & C1) | C2 --> (X | C2) & (C1|C2)
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i8 %C, -2
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i8 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test10
|
|
|
|
; CHECK: ret i8 -2
|
2003-07-24 02:28:42 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i8 @test11(i8 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i8 %A, -2
|
|
|
|
%C = xor i8 %B, 13
|
2008-03-01 17:15:35 +08:00
|
|
|
; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i8 %C, 1
|
|
|
|
%E = xor i8 %D, 12
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i8 %E
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test11
|
|
|
|
; CHECK: ret i8 -1
|
2003-07-24 02:28:42 +08:00
|
|
|
}
|
2003-07-24 03:05:29 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test12(i32 %A) {
|
|
|
|
; Should be eliminated
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i32 %A, 4
|
|
|
|
%C = and i32 %B, 8
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %C
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test12
|
|
|
|
; CHECK: %C = and i32 %A, 8
|
|
|
|
; CHECK: ret i32 %C
|
2003-07-24 03:05:29 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test13(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = or i32 %A, 12
|
2008-03-01 17:15:35 +08:00
|
|
|
; Always equal to 8
|
2009-10-26 07:47:55 +08:00
|
|
|
%C = and i32 %B, 8
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %C
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test13
|
|
|
|
; CHECK: ret i32 8
|
2003-07-24 03:24:34 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test14(i32 %A, i32 %B) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%C1 = icmp ult i32 %A, %B
|
|
|
|
%C2 = icmp ugt i32 %A, %B
|
2008-03-01 17:15:35 +08:00
|
|
|
; (A < B) | (A > B) === A != B
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i1 %C1, %C2
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test14
|
|
|
|
; CHECK: %D = icmp ne i32 %A, %B
|
|
|
|
; CHECK: ret i1 %D
|
2003-07-25 03:31:08 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test15(i32 %A, i32 %B) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%C1 = icmp ult i32 %A, %B
|
|
|
|
%C2 = icmp eq i32 %A, %B
|
2008-03-01 17:15:35 +08:00
|
|
|
; (A < B) | (A == B) === A <= B
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i1 %C1, %C2
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test15
|
|
|
|
; CHECK: %D = icmp ule i32 %A, %B
|
|
|
|
; CHECK: ret i1 %D
|
2003-07-25 03:44:51 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test16(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = and i32 %A, 1
|
2008-03-01 17:15:35 +08:00
|
|
|
; -2 = ~1
|
2009-10-26 07:47:55 +08:00
|
|
|
%C = and i32 %A, -2
|
2008-03-01 17:15:35 +08:00
|
|
|
; %D = and int %B, -1 == %B
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i32 %B, %C
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test16
|
|
|
|
; CHECK: ret i32 %A
|
2003-08-13 03:10:50 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test17(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = and i32 %A, 1
|
|
|
|
%C = and i32 %A, 4
|
2008-03-01 17:15:35 +08:00
|
|
|
; %D = and int %B, 5
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i32 %B, %C
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test17
|
|
|
|
; CHECK: %D = and i32 %A, 5
|
|
|
|
; CHECK: ret i32 %D
|
2003-08-13 03:10:50 +08:00
|
|
|
}
|
2004-09-29 06:31:49 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test18(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = icmp sge i32 %A, 100
|
|
|
|
%C = icmp slt i32 %A, 50
|
2008-03-01 17:15:35 +08:00
|
|
|
;; (A-50) >u 50
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i1 %B, %C
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test18
|
|
|
|
; CHECK: add i32
|
|
|
|
; CHECK: %D = icmp ugt
|
|
|
|
; CHECK: ret i1 %D
|
2004-09-29 06:31:49 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i1 @test19(i32 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = icmp eq i32 %A, 50
|
|
|
|
%C = icmp eq i32 %A, 51
|
2008-03-01 17:15:35 +08:00
|
|
|
;; (A-50) < 2
|
2009-10-26 07:47:55 +08:00
|
|
|
%D = or i1 %B, %C
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i1 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test19
|
|
|
|
; CHECK: add i32
|
|
|
|
; CHECK: %D = icmp ult
|
|
|
|
; CHECK: ret i1 %D
|
2004-09-29 06:31:49 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test20(i32 %x) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%y = and i32 %x, 123
|
|
|
|
%z = or i32 %y, %x
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %z
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test20
|
|
|
|
; CHECK: ret i32 %x
|
2005-05-06 08:58:09 +08:00
|
|
|
}
|
2005-09-18 11:39:02 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test21(i32 %tmp.1) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%tmp.1.mask1 = add i32 %tmp.1, 2
|
|
|
|
%tmp.3 = and i32 %tmp.1.mask1, -2
|
|
|
|
%tmp.5 = and i32 %tmp.1, 1
|
2008-03-01 17:15:35 +08:00
|
|
|
;; add tmp.1, 2
|
2009-10-26 07:47:55 +08:00
|
|
|
%tmp.6 = or i32 %tmp.5, %tmp.3
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %tmp.6
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test21
|
|
|
|
; CHECK: add i32 %{{[^,]*}}, 2
|
|
|
|
; CHECK: ret i32
|
2005-09-18 11:39:02 +08:00
|
|
|
}
|
2006-02-12 16:01:35 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i32 @test22(i32 %B) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%ELIM41 = and i32 %B, 1
|
|
|
|
%ELIM7 = and i32 %B, -2
|
|
|
|
%ELIM5 = or i32 %ELIM41, %ELIM7
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i32 %ELIM5
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test22
|
|
|
|
; CHECK: ret i32 %B
|
2008-03-01 17:15:35 +08:00
|
|
|
}
|
2006-02-27 03:55:30 +08:00
|
|
|
|
2008-03-01 17:15:35 +08:00
|
|
|
define i16 @test23(i16 %A) {
|
2009-10-26 07:47:55 +08:00
|
|
|
%B = lshr i16 %A, 1
|
2008-03-01 17:15:35 +08:00
|
|
|
;; fold or into xor
|
2009-10-26 07:47:55 +08:00
|
|
|
%C = or i16 %B, -32768
|
|
|
|
%D = xor i16 %C, 8193
|
2008-03-01 17:15:35 +08:00
|
|
|
ret i16 %D
|
2009-10-26 07:47:55 +08:00
|
|
|
; CHECK: @test23
|
|
|
|
; CHECK: %B = lshr i16 %A, 1
|
|
|
|
; CHECK: %D = xor i16 %B, -24575
|
|
|
|
; CHECK: ret i16 %D
|
|
|
|
}
|
|
|
|
|
|
|
|
; PR1738
|
|
|
|
define i1 @test24(double %X, double %Y) {
|
|
|
|
%tmp9 = fcmp uno double %X, 0.000000e+00 ; <i1> [#uses=1]
|
|
|
|
%tmp13 = fcmp uno double %Y, 0.000000e+00 ; <i1> [#uses=1]
|
|
|
|
%bothcond = or i1 %tmp13, %tmp9 ; <i1> [#uses=1]
|
|
|
|
ret i1 %bothcond
|
|
|
|
|
|
|
|
; CHECK: @test24
|
|
|
|
; CHECK: %bothcond = fcmp uno double %Y, %X ; <i1> [#uses=1]
|
|
|
|
; CHECK: ret i1 %bothcond
|
2009-10-26 09:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
; PR3266 & PR5276
|
|
|
|
define i1 @test25(i32 %A, i32 %B) {
|
|
|
|
%C = icmp eq i32 %A, 0
|
|
|
|
%D = icmp eq i32 %B, 57
|
|
|
|
%E = or i1 %C, %D
|
|
|
|
%F = xor i1 %E, -1
|
|
|
|
ret i1 %F
|
|
|
|
|
|
|
|
; CHECK: @test25
|
|
|
|
; CHECK: icmp ne i32 %A, 0
|
|
|
|
; CHECK-NEXT: icmp ne i32 %B, 57
|
|
|
|
; CHECK-NEXT: %F = and i1
|
|
|
|
; CHECK-NEXT: ret i1 %F
|
|
|
|
}
|
2009-11-29 08:51:17 +08:00
|
|
|
|
|
|
|
; PR5634
|
|
|
|
define i1 @test26(i32 %A, i32 %B) {
|
|
|
|
%C1 = icmp eq i32 %A, 0
|
|
|
|
%C2 = icmp eq i32 %B, 0
|
|
|
|
; (A == 0) & (A == 0) --> (A|B) == 0
|
|
|
|
%D = and i1 %C1, %C2
|
|
|
|
ret i1 %D
|
|
|
|
; CHECK: @test26
|
|
|
|
; CHECK: or i32 %A, %B
|
|
|
|
; CHECK: icmp eq i32 {{.*}}, 0
|
|
|
|
; CHECK: ret i1
|
|
|
|
}
|
|
|
|
|
2010-01-02 23:25:44 +08:00
|
|
|
define i1 @test27(i32* %A, i32* %B) {
|
|
|
|
%C1 = ptrtoint i32* %A to i32
|
|
|
|
%C2 = ptrtoint i32* %B to i32
|
|
|
|
%D = or i32 %C1, %C2
|
|
|
|
%E = icmp eq i32 %D, 0
|
|
|
|
ret i1 %E
|
|
|
|
; CHECK: @test27
|
|
|
|
; CHECK: icmp eq i32* %A, null
|
|
|
|
; CHECK: icmp eq i32* %B, null
|
|
|
|
; CHECK: and i1
|
|
|
|
; CHECK: ret i1
|
|
|
|
}
|
|
|
|
|
2009-11-29 08:51:17 +08:00
|
|
|
; PR5634
|
|
|
|
define i1 @test28(i32 %A, i32 %B) {
|
|
|
|
%C1 = icmp ne i32 %A, 0
|
|
|
|
%C2 = icmp ne i32 %B, 0
|
|
|
|
; (A != 0) | (A != 0) --> (A|B) != 0
|
|
|
|
%D = or i1 %C1, %C2
|
|
|
|
ret i1 %D
|
|
|
|
; CHECK: @test28
|
|
|
|
; CHECK: or i32 %A, %B
|
|
|
|
; CHECK: icmp ne i32 {{.*}}, 0
|
|
|
|
; CHECK: ret i1
|
|
|
|
}
|
2010-01-03 00:14:56 +08:00
|
|
|
|
|
|
|
define i1 @test29(i32* %A, i32* %B) {
|
|
|
|
%C1 = ptrtoint i32* %A to i32
|
|
|
|
%C2 = ptrtoint i32* %B to i32
|
|
|
|
%D = or i32 %C1, %C2
|
|
|
|
%E = icmp ne i32 %D, 0
|
|
|
|
ret i1 %E
|
|
|
|
; CHECK: @test29
|
|
|
|
; CHECK: icmp ne i32* %A, null
|
|
|
|
; CHECK: icmp ne i32* %B, null
|
|
|
|
; CHECK: or i1
|
|
|
|
; CHECK: ret i1
|
|
|
|
}
|
|
|
|
|
2010-01-04 14:03:59 +08:00
|
|
|
; PR4216
|
|
|
|
define i32 @test30(i32 %A) {
|
|
|
|
entry:
|
|
|
|
%B = or i32 %A, 32962
|
|
|
|
%C = and i32 %A, -65536
|
|
|
|
%D = and i32 %B, 40186
|
|
|
|
%E = or i32 %D, %C
|
|
|
|
ret i32 %E
|
|
|
|
; CHECK: @test30
|
|
|
|
; CHECK: %B = or i32 %A, 32962
|
|
|
|
; CHECK: %E = and i32 %B, -25350
|
|
|
|
; CHECK: ret i32 %E
|
|
|
|
}
|