diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-01-18 18:54:33 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-01-18 18:54:33 +0000 |
commit | 75153960965e95e0e048add9cee0de310e05d4fe (patch) | |
tree | 7389dda3099ed03f7f32a686bbb6d6b3d62e0e45 | |
parent | b5f378e11b7bdcf4a81c98ec535cc487ab9a92f9 (diff) | |
download | llvm-75153960965e95e0e048add9cee0de310e05d4fe.tar.gz llvm-75153960965e95e0e048add9cee0de310e05d4fe.tar.bz2 llvm-75153960965e95e0e048add9cee0de310e05d4fe.tar.xz |
Clean up some code around the store V, (cast P) -> store (cast V), P
transform. Change some variable names so it is clear what is source and
what is dest of the cast. Also, add an assert to ensure that the integer
to integer case is asserting if the bitwidths are different. This prevents
illegal casts from being formed and catches bitwidth bugs sooner.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33337 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index f81f10e71e..48eaef59e7 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8186,23 +8186,29 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) { IC.getTargetData().getTypeSize(DestPTy)) { // Okay, we are casting from one integer or pointer type to another of - // the same size. Instead of casting the pointer before the store, cast - // the value to be stored. + // the same size. Instead of casting the pointer before + // the store, cast the value to be stored. Value *NewCast; - Instruction::CastOps opcode = Instruction::BitCast; Value *SIOp0 = SI.getOperand(0); - if (isa<PointerType>(SrcPTy)) { - if (SIOp0->getType()->isInteger()) + Instruction::CastOps opcode = Instruction::BitCast; + const Type* CastSrcTy = SIOp0->getType(); + const Type* CastDstTy = SrcPTy; + if (isa<PointerType>(CastDstTy)) { + if (CastSrcTy->isInteger()) opcode = Instruction::IntToPtr; - } else if (SrcPTy->isInteger()) { + } else if (const IntegerType* DITy = dyn_cast<IntegerType>(CastDstTy)) { if (isa<PointerType>(SIOp0->getType())) opcode = Instruction::PtrToInt; + else if (const IntegerType* SITy = dyn_cast<IntegerType>(CastSrcTy)) + assert(DITy->getBitWidth() == SITy->getBitWidth() && + "Illegal store instruction"); } if (Constant *C = dyn_cast<Constant>(SIOp0)) - NewCast = ConstantExpr::getCast(opcode, C, SrcPTy); + NewCast = ConstantExpr::getCast(opcode, C, CastDstTy); else NewCast = IC.InsertNewInstBefore( - CastInst::create(opcode, SIOp0, SrcPTy, SIOp0->getName()+".c"), SI); + CastInst::create(opcode, SIOp0, CastDstTy, SIOp0->getName()+".c"), + SI); return new StoreInst(NewCast, CastOp); } } |