diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-08-27 20:32:06 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-08-27 20:32:06 +0000 |
| commit | 739843467598e7ca95e9d0be12b538ace682a00a (patch) | |
| tree | f093cbe37fce1c2c07a8bdfdc4e8f16b94dd5cea | |
| parent | 167fd1084bcb59dc26d3d3e9b993723800c478b9 (diff) | |
| download | bcm5719-llvm-739843467598e7ca95e9d0be12b538ace682a00a.tar.gz bcm5719-llvm-739843467598e7ca95e9d0be12b538ace682a00a.zip | |
teach the truncation optimization that an entire chain of
computation can be truncated if it is fed by a sext/zext that doesn't
have to be exactly equal to the truncation result type.
llvm-svn: 112285
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 5 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/trunc.ll | 25 |
2 files changed, 26 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 1372a1891fa..89719bef09e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -396,6 +396,11 @@ static bool CanEvaluateTruncated(Value *V, const Type *Ty) { case Instruction::Trunc: // trunc(trunc(x)) -> trunc(x) return true; + case Instruction::ZExt: + case Instruction::SExt: + // trunc(ext(x)) -> ext(x) if the source type is smaller than the new dest + // trunc(ext(x)) -> trunc(x) if the source type is larger than the new dest + return true; case Instruction::Select: { SelectInst *SI = cast<SelectInst>(I); return CanEvaluateTruncated(SI->getTrueValue(), Ty) && diff --git a/llvm/test/Transforms/InstCombine/trunc.ll b/llvm/test/Transforms/InstCombine/trunc.ll index 5cb34746676..f98bfd9236c 100644 --- a/llvm/test/Transforms/InstCombine/trunc.ll +++ b/llvm/test/Transforms/InstCombine/trunc.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -instcombine -S | FileCheck %s +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" ; Instcombine should be able to eliminate all of these ext casts. @@ -76,7 +77,23 @@ define i92 @test7(i64 %A) { %D = trunc i128 %C to i92 ret i92 %D ; CHECK: @test7 -; CHECK: %C = lshr i64 %A, 32 -; CHECK: %D = zext i64 %C to i92 -; CHECK: ret i92 %D -}
\ No newline at end of file +; CHECK: %B = zext i64 %A to i92 +; CHECK: %C = lshr i92 %B, 32 +; CHECK: ret i92 %C +} + +define i64 @test8(i32 %A, i32 %B) { + %tmp38 = zext i32 %A to i128 + %tmp32 = zext i32 %B to i128 + %tmp33 = shl i128 %tmp32, 32 + %ins35 = or i128 %tmp33, %tmp38 + %tmp42 = trunc i128 %ins35 to i64 + ret i64 %tmp42 +; CHECK: @test8 +; CHECK: %tmp38 = zext i32 %A to i64 +; CHECK: %tmp32 = zext i32 %B to i64 +; CHECK: %tmp33 = shl i64 %tmp32, 32 +; CHECK: %ins35 = or i64 %tmp33, %tmp38 +; CHECK: ret i64 %ins35 +} + |

