llvm-project/llvm/test/Transforms/InstCombine/add-shrink.ll

17 lines
433 B
LLVM
Raw Normal View History

; RUN: opt < %s -instcombine -S | FileCheck %s
Teach instcombine 4 new xforms: (add (sext x), cst) --> (sext (add x, cst')) (add (sext x), (sext y)) --> (sext (add int x, y)) (add double (sitofp x), fpcst) --> (sitofp (add int x, intcst)) (add double (sitofp x), (sitofp y)) --> (sitofp (add int x, y)) This generally reduces conversions. For example MiBench/telecomm-gsm gets these simplifications: HACK2: %tmp67.i142.i.i = sext i16 %tmp6.i141.i.i to i32 ; <i32> [#uses=1] %tmp23.i139.i.i = sext i16 %tmp2.i138.i.i to i32 ; <i32> [#uses=1] %tmp8.i143.i.i = add i32 %tmp67.i142.i.i, %tmp23.i139.i.i ; <i32> [#uses=3] HACK2: %tmp67.i121.i.i = sext i16 %tmp6.i120.i.i to i32 ; <i32> [#uses=1] %tmp23.i118.i.i = sext i16 %tmp2.i117.i.i to i32 ; <i32> [#uses=1] %tmp8.i122.i.i = add i32 %tmp67.i121.i.i, %tmp23.i118.i.i ; <i32> [#uses=3] HACK2: %tmp67.i.i190.i = sext i16 %tmp6.i.i189.i to i32 ; <i32> [#uses=1] %tmp23.i.i187.i = sext i16 %tmp2.i.i186.i to i32 ; <i32> [#uses=1] %tmp8.i.i191.i = add i32 %tmp67.i.i190.i, %tmp23.i.i187.i ; <i32> [#uses=3] HACK2: %tmp67.i173.i.i.i = sext i16 %tmp6.i172.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i170.i.i.i = sext i16 %tmp2.i169.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i174.i.i.i = add i32 %tmp67.i173.i.i.i, %tmp23.i170.i.i.i ; <i32> [#uses=3] HACK2: %tmp67.i152.i.i.i = sext i16 %tmp6.i151.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i149.i.i.i = sext i16 %tmp2.i148.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i153.i.i.i = add i32 %tmp67.i152.i.i.i, %tmp23.i149.i.i.i ; <i32> [#uses=3] HACK2: %tmp67.i.i.i.i = sext i16 %tmp6.i.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i.i5.i.i = sext i16 %tmp2.i.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i.i7.i.i = add i32 %tmp67.i.i.i.i, %tmp23.i.i5.i.i ; <i32> [#uses=3] This also fixes a bug in ComputeNumSignBits handling select and makes it more aggressive with and/or. llvm-svn: 51302
2008-05-20 13:46:13 +08:00
; CHECK-LABEL: define i64 @test
Teach instcombine 4 new xforms: (add (sext x), cst) --> (sext (add x, cst')) (add (sext x), (sext y)) --> (sext (add int x, y)) (add double (sitofp x), fpcst) --> (sitofp (add int x, intcst)) (add double (sitofp x), (sitofp y)) --> (sitofp (add int x, y)) This generally reduces conversions. For example MiBench/telecomm-gsm gets these simplifications: HACK2: %tmp67.i142.i.i = sext i16 %tmp6.i141.i.i to i32 ; <i32> [#uses=1] %tmp23.i139.i.i = sext i16 %tmp2.i138.i.i to i32 ; <i32> [#uses=1] %tmp8.i143.i.i = add i32 %tmp67.i142.i.i, %tmp23.i139.i.i ; <i32> [#uses=3] HACK2: %tmp67.i121.i.i = sext i16 %tmp6.i120.i.i to i32 ; <i32> [#uses=1] %tmp23.i118.i.i = sext i16 %tmp2.i117.i.i to i32 ; <i32> [#uses=1] %tmp8.i122.i.i = add i32 %tmp67.i121.i.i, %tmp23.i118.i.i ; <i32> [#uses=3] HACK2: %tmp67.i.i190.i = sext i16 %tmp6.i.i189.i to i32 ; <i32> [#uses=1] %tmp23.i.i187.i = sext i16 %tmp2.i.i186.i to i32 ; <i32> [#uses=1] %tmp8.i.i191.i = add i32 %tmp67.i.i190.i, %tmp23.i.i187.i ; <i32> [#uses=3] HACK2: %tmp67.i173.i.i.i = sext i16 %tmp6.i172.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i170.i.i.i = sext i16 %tmp2.i169.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i174.i.i.i = add i32 %tmp67.i173.i.i.i, %tmp23.i170.i.i.i ; <i32> [#uses=3] HACK2: %tmp67.i152.i.i.i = sext i16 %tmp6.i151.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i149.i.i.i = sext i16 %tmp2.i148.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i153.i.i.i = add i32 %tmp67.i152.i.i.i, %tmp23.i149.i.i.i ; <i32> [#uses=3] HACK2: %tmp67.i.i.i.i = sext i16 %tmp6.i.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i.i5.i.i = sext i16 %tmp2.i.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i.i7.i.i = add i32 %tmp67.i.i.i.i, %tmp23.i.i5.i.i ; <i32> [#uses=3] This also fixes a bug in ComputeNumSignBits handling select and makes it more aggressive with and/or. llvm-svn: 51302
2008-05-20 13:46:13 +08:00
define i64 @test1(i32 %A) {
; CHECK: %[[ADD:.*]] = add nsw i32 %B, %C
; CHECK: %F = sext i32 %[[ADD]] to i64
; CHECK: ret i64 %F
Teach instcombine 4 new xforms: (add (sext x), cst) --> (sext (add x, cst')) (add (sext x), (sext y)) --> (sext (add int x, y)) (add double (sitofp x), fpcst) --> (sitofp (add int x, intcst)) (add double (sitofp x), (sitofp y)) --> (sitofp (add int x, y)) This generally reduces conversions. For example MiBench/telecomm-gsm gets these simplifications: HACK2: %tmp67.i142.i.i = sext i16 %tmp6.i141.i.i to i32 ; <i32> [#uses=1] %tmp23.i139.i.i = sext i16 %tmp2.i138.i.i to i32 ; <i32> [#uses=1] %tmp8.i143.i.i = add i32 %tmp67.i142.i.i, %tmp23.i139.i.i ; <i32> [#uses=3] HACK2: %tmp67.i121.i.i = sext i16 %tmp6.i120.i.i to i32 ; <i32> [#uses=1] %tmp23.i118.i.i = sext i16 %tmp2.i117.i.i to i32 ; <i32> [#uses=1] %tmp8.i122.i.i = add i32 %tmp67.i121.i.i, %tmp23.i118.i.i ; <i32> [#uses=3] HACK2: %tmp67.i.i190.i = sext i16 %tmp6.i.i189.i to i32 ; <i32> [#uses=1] %tmp23.i.i187.i = sext i16 %tmp2.i.i186.i to i32 ; <i32> [#uses=1] %tmp8.i.i191.i = add i32 %tmp67.i.i190.i, %tmp23.i.i187.i ; <i32> [#uses=3] HACK2: %tmp67.i173.i.i.i = sext i16 %tmp6.i172.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i170.i.i.i = sext i16 %tmp2.i169.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i174.i.i.i = add i32 %tmp67.i173.i.i.i, %tmp23.i170.i.i.i ; <i32> [#uses=3] HACK2: %tmp67.i152.i.i.i = sext i16 %tmp6.i151.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i149.i.i.i = sext i16 %tmp2.i148.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i153.i.i.i = add i32 %tmp67.i152.i.i.i, %tmp23.i149.i.i.i ; <i32> [#uses=3] HACK2: %tmp67.i.i.i.i = sext i16 %tmp6.i.i.i.i to i32 ; <i32> [#uses=1] %tmp23.i.i5.i.i = sext i16 %tmp2.i.i.i.i to i32 ; <i32> [#uses=1] %tmp8.i.i7.i.i = add i32 %tmp67.i.i.i.i, %tmp23.i.i5.i.i ; <i32> [#uses=3] This also fixes a bug in ComputeNumSignBits handling select and makes it more aggressive with and/or. llvm-svn: 51302
2008-05-20 13:46:13 +08:00
%B = ashr i32 %A, 7 ; <i32> [#uses=1]
%C = ashr i32 %A, 9 ; <i32> [#uses=1]
%D = sext i32 %B to i64 ; <i64> [#uses=1]
%E = sext i32 %C to i64 ; <i64> [#uses=1]
%F = add i64 %D, %E ; <i64> [#uses=1]
ret i64 %F
}