diff options
author | Chris Lattner <sabre@nondot.org> | 2004-04-12 00:23:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-04-12 00:23:04 +0000 |
commit | 9938286325f708e076fb8824697aa1478727b78f (patch) | |
tree | 10f14e770c6c2d61c0e0d85ecd4ed39ccfc7cf1a /lib | |
parent | 13c07feb20be193a1c5e6bc0a27ff428d5a7ab6f (diff) | |
download | external_llvm-9938286325f708e076fb8824697aa1478727b78f.zip external_llvm-9938286325f708e076fb8824697aa1478727b78f.tar.gz external_llvm-9938286325f708e076fb8824697aa1478727b78f.tar.bz2 |
Fix a bug in my load/cast folding patch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/X86/InstSelectSimple.cpp | 26 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelSimple.cpp | 26 |
2 files changed, 28 insertions, 24 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp index 2477da0..a2e7e66 100644 --- a/lib/Target/X86/InstSelectSimple.cpp +++ b/lib/Target/X86/InstSelectSimple.cpp @@ -2759,15 +2759,17 @@ void ISel::visitStoreInst(StoreInst &I) { void ISel::visitCastInst(CastInst &CI) { Value *Op = CI.getOperand(0); - // Noop casts are not even emitted. - if (getClassB(CI.getType()) == getClassB(Op->getType())) + unsigned SrcClass = getClassB(Op->getType()); + unsigned DestClass = getClassB(CI.getType()); + // Noop casts are not emitted: getReg will return the source operand as the + // register to use for any uses of the noop cast. + if (DestClass == SrcClass) return; // If this is a cast from a 32-bit integer to a Long type, and the only uses // of the case are GEP instructions, then the cast does not need to be // generated explicitly, it will be folded into the GEP. - if (CI.getType() == Type::LongTy && - (Op->getType() == Type::IntTy || Op->getType() == Type::UIntTy)) { + if (DestClass == cLong && SrcClass == cInt) { bool AllUsesAreGEPs = true; for (Value::use_iterator I = CI.use_begin(), E = CI.use_end(); I != E; ++I) if (!isa<GetElementPtrInst>(*I)) { @@ -2779,6 +2781,14 @@ void ISel::visitCastInst(CastInst &CI) { if (AllUsesAreGEPs) return; } + // If this cast converts a load from a short,int, or long integer to a FP + // value, we will have folded this cast away. + if (DestClass == cFP && isa<LoadInst>(Op) && Op->hasOneUse() && + (Op->getType() == Type::ShortTy || Op->getType() == Type::IntTy || + Op->getType() == Type::LongTy)) + return; + + unsigned DestReg = getReg(CI); MachineBasicBlock::iterator MI = BB->end(); emitCastOperation(BB, MI, Op, CI.getType(), DestReg); @@ -2794,14 +2804,6 @@ void ISel::emitCastOperation(MachineBasicBlock *BB, const Type *SrcTy = Src->getType(); unsigned SrcClass = getClassB(SrcTy); unsigned DestClass = getClassB(DestTy); - - // If this cast converts a load from a short,int, or long integer to a FP - // value, we will have folded this cast away. - if (DestClass == cFP && isa<LoadInst>(Src) && - (Src->getType() == Type::ShortTy || Src->getType() == Type::IntTy || - Src->getType() == Type::LongTy)) - return; - unsigned SrcReg = getReg(Src, BB, IP); // Implement casts to bool by using compare on the operand followed by set if diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp index 2477da0..a2e7e66 100644 --- a/lib/Target/X86/X86ISelSimple.cpp +++ b/lib/Target/X86/X86ISelSimple.cpp @@ -2759,15 +2759,17 @@ void ISel::visitStoreInst(StoreInst &I) { void ISel::visitCastInst(CastInst &CI) { Value *Op = CI.getOperand(0); - // Noop casts are not even emitted. - if (getClassB(CI.getType()) == getClassB(Op->getType())) + unsigned SrcClass = getClassB(Op->getType()); + unsigned DestClass = getClassB(CI.getType()); + // Noop casts are not emitted: getReg will return the source operand as the + // register to use for any uses of the noop cast. + if (DestClass == SrcClass) return; // If this is a cast from a 32-bit integer to a Long type, and the only uses // of the case are GEP instructions, then the cast does not need to be // generated explicitly, it will be folded into the GEP. - if (CI.getType() == Type::LongTy && - (Op->getType() == Type::IntTy || Op->getType() == Type::UIntTy)) { + if (DestClass == cLong && SrcClass == cInt) { bool AllUsesAreGEPs = true; for (Value::use_iterator I = CI.use_begin(), E = CI.use_end(); I != E; ++I) if (!isa<GetElementPtrInst>(*I)) { @@ -2779,6 +2781,14 @@ void ISel::visitCastInst(CastInst &CI) { if (AllUsesAreGEPs) return; } + // If this cast converts a load from a short,int, or long integer to a FP + // value, we will have folded this cast away. + if (DestClass == cFP && isa<LoadInst>(Op) && Op->hasOneUse() && + (Op->getType() == Type::ShortTy || Op->getType() == Type::IntTy || + Op->getType() == Type::LongTy)) + return; + + unsigned DestReg = getReg(CI); MachineBasicBlock::iterator MI = BB->end(); emitCastOperation(BB, MI, Op, CI.getType(), DestReg); @@ -2794,14 +2804,6 @@ void ISel::emitCastOperation(MachineBasicBlock *BB, const Type *SrcTy = Src->getType(); unsigned SrcClass = getClassB(SrcTy); unsigned DestClass = getClassB(DestTy); - - // If this cast converts a load from a short,int, or long integer to a FP - // value, we will have folded this cast away. - if (DestClass == cFP && isa<LoadInst>(Src) && - (Src->getType() == Type::ShortTy || Src->getType() == Type::IntTy || - Src->getType() == Type::LongTy)) - return; - unsigned SrcReg = getReg(Src, BB, IP); // Implement casts to bool by using compare on the operand followed by set if |