diff options
| author | Chris Lattner <sabre@nondot.org> | 2002-08-14 23:21:10 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2002-08-14 23:21:10 +0000 |
| commit | 0bb75910e2ac99a01f89673af926b9bb9aedcb61 (patch) | |
| tree | d18c56dbce936808582f8e750db72020522a6b09 /llvm/lib/Transforms | |
| parent | ac4e8c6ea49276d40c52db21a08044c6f8680b7f (diff) | |
| download | bcm5719-llvm-0bb75910e2ac99a01f89673af926b9bb9aedcb61.tar.gz bcm5719-llvm-0bb75910e2ac99a01f89673af926b9bb9aedcb61.zip | |
Implement capability to fold this:
uint %test4(int %A, int %B) {
%COND = setlt int %A, %B ; <bool> [#uses=1]
%result = cast bool %COND to uint ; <uint> [#uses=1]
ret uint %result
}
into a single cast instruction.
llvm-svn: 3339
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 366752f2d64..cc00093c78a 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -476,6 +476,13 @@ Instruction *InstCombiner::visitShiftInst(Instruction &I) { } +// isCIntegral - For the purposes of casting, we allow conversion of sizes and +// stuff as long as the value type acts basically integral like. +// +static bool isCIntegral(const Type *Ty) { + return Ty->isIntegral() || Ty == Type::BoolTy; +} + // isEliminableCastOfCast - Return true if it is valid to eliminate the CI // instruction. // @@ -488,13 +495,13 @@ static inline bool isEliminableCastOfCast(const CastInst &CI, // It is legal to eliminate the instruction if casting A->B->A if the sizes // are identical and the bits don't get reinterpreted (for example - // int->float->int) + // int->float->int would not be allowed) if (SrcTy == DstTy && SrcTy->isLosslesslyConvertableTo(MidTy)) return true; // Allow free casting and conversion of sizes as long as the sign doesn't // change... - if (SrcTy->isIntegral() && MidTy->isIntegral() && DstTy->isIntegral() && + if (isCIntegral(SrcTy) && isCIntegral(MidTy) && isCIntegral(DstTy) && SrcTy->isSigned() == MidTy->isSigned() && MidTy->isSigned() == DstTy->isSigned()) { // Only accept cases where we are either monotonically increasing the type @@ -503,10 +510,10 @@ static inline bool isEliminableCastOfCast(const CastInst &CI, unsigned SrcSize = SrcTy->getPrimitiveSize(); unsigned MidSize = MidTy->getPrimitiveSize(); unsigned DstSize = DstTy->getPrimitiveSize(); - if (SrcSize < MidSize && MidSize < DstSize) + if (SrcSize <= MidSize && MidSize <= DstSize) return true; - if (SrcSize > MidSize && MidSize > DstSize) + if (SrcSize >= MidSize && MidSize >= DstSize) return true; } |

