llvm-6502/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
Duncan Sands 566edb04b8 Add generic simplification of associative operations, generalizing
a couple of existing transforms.  This fires surprisingly often, for
example when compiling gcc "(X+(-1))+1->X" fires quite a lot as well
as various "and" simplifications (usually with a phi node operand).
Most of the time this doesn't make a real difference since the same
thing would have been done elsewhere anyway, eg: by instcombine, but
there are a few places where this results in simplifications that we
were not doing before.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122326 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 08:49:00 +00:00

65 lines
1.1 KiB
LLVM

; RUN: opt < %s -instsimplify -S | FileCheck %s
define i32 @add1(i32 %x) {
; CHECK: @add1
; (X + -1) + 1 -> X
%l = add i32 %x, -1
%r = add i32 %l, 1
ret i32 %r
; CHECK: ret i32 %x
}
define i32 @and1(i32 %x, i32 %y) {
; CHECK: @and1
; (X & Y) & X -> X & Y
%l = and i32 %x, %y
%r = and i32 %l, %x
ret i32 %r
; CHECK: ret i32 %l
}
define i32 @and2(i32 %x, i32 %y) {
; CHECK: @and2
; X & (X & Y) -> X & Y
%r = and i32 %x, %y
%l = and i32 %x, %r
ret i32 %l
; CHECK: ret i32 %r
}
define i32 @or1(i32 %x, i32 %y) {
; CHECK: @or1
; (X | Y) | X -> X | Y
%l = or i32 %x, %y
%r = or i32 %l, %x
ret i32 %r
; CHECK: ret i32 %l
}
define i32 @or2(i32 %x, i32 %y) {
; CHECK: @or2
; X | (X | Y) -> X | Y
%r = or i32 %x, %y
%l = or i32 %x, %r
ret i32 %l
; CHECK: ret i32 %r
}
define i32 @xor1(i32 %x, i32 %y) {
; CHECK: @xor1
; (X ^ Y) ^ X = Y
%l = xor i32 %x, %y
%r = xor i32 %l, %x
ret i32 %r
; CHECK: ret i32 %y
}
define i32 @xor2(i32 %x, i32 %y) {
; CHECK: @xor2
; X ^ (X ^ Y) = Y
%r = xor i32 %x, %y
%l = xor i32 %x, %r
ret i32 %l
; CHECK: ret i32 %y
}