summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-08-06 05:13:06 +0000
committerChris Lattner <sabre@nondot.org>2008-08-06 05:13:06 +0000
commit7bdaecb7f497fa82f13fb640a4bc1e6a5245ede8 (patch)
tree2a15fd6a733439273901c117999e653895a2013c /llvm/lib/Transforms
parentead7c9124033ab3bcc3f2bd44145ccb5afeeafcd (diff)
downloadbcm5719-llvm-7bdaecb7f497fa82f13fb640a4bc1e6a5245ede8.tar.gz
bcm5719-llvm-7bdaecb7f497fa82f13fb640a4bc1e6a5245ede8.zip
Zap sitofp/fptoui pairs. In all cases when the sign difference
matters, the result is undefined anyway. llvm-svn: 54396
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index fbd0d200717..44083bc2d00 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -7750,27 +7750,41 @@ Instruction *InstCombiner::visitFPExt(CastInst &CI) {
}
Instruction *InstCombiner::visitFPToUI(FPToUIInst &FI) {
- // fptoui(uitofp(X)) --> X if the intermediate type has enough bits in its
- // mantissa to accurately represent all values of X. For example, do not
- // do this with i64->float->i64.
- if (UIToFPInst *SrcI = dyn_cast<UIToFPInst>(FI.getOperand(0)))
- if (SrcI->getOperand(0)->getType() == FI.getType() &&
- (int)FI.getType()->getPrimitiveSizeInBits() < /*extra bit for sign */
- SrcI->getType()->getFPMantissaWidth())
- return ReplaceInstUsesWith(FI, SrcI->getOperand(0));
+ Instruction *OpI = dyn_cast<Instruction>(FI.getOperand(0));
+ if (OpI == 0)
+ return commonCastTransforms(FI);
+
+ // fptoui(uitofp(X)) --> X
+ // fptoui(sitofp(X)) --> X
+ // This is safe if the intermediate type has enough bits in its mantissa to
+ // accurately represent all values of X. For example, do not do this with
+ // i64->float->i64. This is also safe for sitofp case, because any negative
+ // 'X' value would cause an undefined result for the fptoui.
+ if ((isa<UIToFPInst>(OpI) || isa<SIToFPInst>(OpI)) &&
+ OpI->getOperand(0)->getType() == FI.getType() &&
+ (int)FI.getType()->getPrimitiveSizeInBits() < /*extra bit for sign */
+ OpI->getType()->getFPMantissaWidth())
+ return ReplaceInstUsesWith(FI, OpI->getOperand(0));
return commonCastTransforms(FI);
}
Instruction *InstCombiner::visitFPToSI(FPToSIInst &FI) {
- // fptosi(sitofp(X)) --> X if the intermediate type has enough bits in its
- // mantissa to accurately represent all values of X. For example, do not
- // do this with i64->float->i64.
- if (SIToFPInst *SrcI = dyn_cast<SIToFPInst>(FI.getOperand(0)))
- if (SrcI->getOperand(0)->getType() == FI.getType() &&
- (int)FI.getType()->getPrimitiveSizeInBits() <=
- SrcI->getType()->getFPMantissaWidth())
- return ReplaceInstUsesWith(FI, SrcI->getOperand(0));
+ Instruction *OpI = dyn_cast<Instruction>(FI.getOperand(0));
+ if (OpI == 0)
+ return commonCastTransforms(FI);
+
+ // fptosi(sitofp(X)) --> X
+ // fptosi(uitofp(X)) --> X
+ // This is safe if the intermediate type has enough bits in its mantissa to
+ // accurately represent all values of X. For example, do not do this with
+ // i64->float->i64. This is also safe for sitofp case, because any negative
+ // 'X' value would cause an undefined result for the fptoui.
+ if ((isa<UIToFPInst>(OpI) || isa<SIToFPInst>(OpI)) &&
+ OpI->getOperand(0)->getType() == FI.getType() &&
+ (int)FI.getType()->getPrimitiveSizeInBits() <=
+ OpI->getType()->getFPMantissaWidth())
+ return ReplaceInstUsesWith(FI, OpI->getOperand(0));
return commonCastTransforms(FI);
}
OpenPOWER on IntegriCloud