2007-04-03 03:45:32 +02:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
|
|
|
;
|
2009-10-11 23:42:08 +02:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2007-04-03 03:45:32 +02:00
|
|
|
|
|
|
|
; PR1253
|
|
|
|
define i1 @test0(i32 %A) {
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test0(
|
2009-10-11 23:42:08 +02:00
|
|
|
; CHECK: %C = icmp slt i32 %A, 0
|
2007-04-03 03:45:32 +02:00
|
|
|
%B = xor i32 %A, -2147483648
|
|
|
|
%C = icmp sgt i32 %B, -1
|
|
|
|
ret i1 %C
|
|
|
|
}
|
|
|
|
|
|
|
|
define i1 @test1(i32 %A) {
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test1(
|
2009-10-11 23:42:08 +02:00
|
|
|
; CHECK: %C = icmp slt i32 %A, 0
|
2007-04-03 03:45:32 +02:00
|
|
|
%B = xor i32 %A, 12345
|
|
|
|
%C = icmp slt i32 %B, 0
|
|
|
|
ret i1 %C
|
|
|
|
}
|
|
|
|
|
2009-10-11 23:42:08 +02:00
|
|
|
; PR1014
|
|
|
|
define i32 @test2(i32 %tmp1) {
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test2(
|
2010-03-03 01:35:56 +01:00
|
|
|
; CHECK-NEXT: and i32 %tmp1, 32
|
|
|
|
; CHECK-NEXT: or i32 %ovm, 8
|
2009-10-11 23:42:08 +02:00
|
|
|
; CHECK-NEXT: ret i32
|
|
|
|
%ovm = and i32 %tmp1, 32
|
|
|
|
%ov3 = add i32 %ovm, 145
|
|
|
|
%ov110 = xor i32 %ov3, 153
|
|
|
|
ret i32 %ov110
|
|
|
|
}
|
2009-10-12 00:22:13 +02:00
|
|
|
|
|
|
|
define i32 @test3(i32 %tmp1) {
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test3(
|
2010-03-03 01:35:56 +01:00
|
|
|
; CHECK-NEXT: and i32 %tmp1, 32
|
2010-09-13 19:59:27 +02:00
|
|
|
; CHECK-NEXT: or i32 %ovm, 8
|
2009-10-12 00:22:13 +02:00
|
|
|
; CHECK-NEXT: ret i32
|
|
|
|
%ovm = or i32 %tmp1, 145
|
|
|
|
%ov31 = and i32 %ovm, 177
|
|
|
|
%ov110 = xor i32 %ov31, 153
|
|
|
|
ret i32 %ov110
|
|
|
|
}
|
2010-01-19 19:16:19 +01:00
|
|
|
|
|
|
|
define i32 @test4(i32 %A, i32 %B) {
|
|
|
|
%1 = xor i32 %A, -1
|
|
|
|
%2 = ashr i32 %1, %B
|
|
|
|
%3 = xor i32 %2, -1
|
|
|
|
ret i32 %3
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test4(
|
2010-01-19 19:16:19 +01:00
|
|
|
; CHECK: %1 = ashr i32 %A, %B
|
|
|
|
; CHECK: ret i32 %1
|
|
|
|
}
|
2012-11-26 22:44:25 +01:00
|
|
|
|
|
|
|
; defect-2 in rdar://12329730
|
|
|
|
; (X^C1) >> C2) ^ C3 -> (X>>C2) ^ ((C1>>C2)^C3)
|
|
|
|
; where the "X" has more than one use
|
|
|
|
define i32 @test5(i32 %val1) {
|
|
|
|
test5:
|
|
|
|
%xor = xor i32 %val1, 1234
|
|
|
|
%shr = lshr i32 %xor, 8
|
|
|
|
%xor1 = xor i32 %shr, 1
|
|
|
|
%add = add i32 %xor1, %xor
|
|
|
|
ret i32 %add
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test5(
|
2012-11-26 22:44:25 +01:00
|
|
|
; CHECK: lshr i32 %val1, 8
|
|
|
|
; CHECK: ret
|
|
|
|
}
|
2012-12-04 23:15:32 +01:00
|
|
|
|
|
|
|
; defect-1 in rdar://12329730
|
|
|
|
; Simplify (X^Y) -> X or Y in the user's context if we know that
|
|
|
|
; only bits from X or Y are demanded.
|
|
|
|
; e.g. the "x ^ 1234" can be optimized into x in the context of "t >> 16".
|
|
|
|
; Put in other word, t >> 16 -> x >> 16.
|
2012-12-05 01:33:16 +01:00
|
|
|
; unsigned foo(unsigned x) { unsigned t = x ^ 1234; ; return (t >> 16) + t;}
|
2012-12-04 23:15:32 +01:00
|
|
|
define i32 @test6(i32 %x) {
|
|
|
|
%xor = xor i32 %x, 1234
|
|
|
|
%shr = lshr i32 %xor, 16
|
|
|
|
%add = add i32 %shr, %xor
|
|
|
|
ret i32 %add
|
2013-07-14 03:42:54 +02:00
|
|
|
; CHECK-LABEL: @test6(
|
2012-12-04 23:15:32 +01:00
|
|
|
; CHECK: lshr i32 %x, 16
|
|
|
|
; CHECK: ret
|
|
|
|
}
|