mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-11 05:17:36 +00:00
eliminate InsertBitCastBefore, just use the builder instead.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80504 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a07ae6be66
commit
08142f2560
@ -319,11 +319,6 @@ namespace {
|
|||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *InsertBitCastBefore(Value *V, const Type *Ty, Instruction &Pos) {
|
|
||||||
return InsertCastBefore(Instruction::BitCast, V, Ty, Pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ReplaceInstUsesWith - This method is to be used when an instruction is
|
// ReplaceInstUsesWith - This method is to be used when an instruction is
|
||||||
// found to be dead, replacable with another preexisting expression. Here
|
// found to be dead, replacable with another preexisting expression. Here
|
||||||
// we add all uses of I to the worklist, replace all uses of I with the new
|
// we add all uses of I to the worklist, replace all uses of I with the new
|
||||||
@ -1896,9 +1891,8 @@ struct AddMaskingAnd {
|
|||||||
|
|
||||||
static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
||||||
InstCombiner *IC) {
|
InstCombiner *IC) {
|
||||||
if (CastInst *CI = dyn_cast<CastInst>(&I)) {
|
if (CastInst *CI = dyn_cast<CastInst>(&I))
|
||||||
return IC->InsertCastBefore(CI->getOpcode(), SO, I.getType(), I);
|
return IC->InsertCastBefore(CI->getOpcode(), SO, I.getType(), I);
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out if the constant is the left or the right argument.
|
// Figure out if the constant is the left or the right argument.
|
||||||
bool ConstIsRHS = isa<Constant>(I.getOperand(1));
|
bool ConstIsRHS = isa<Constant>(I.getOperand(1));
|
||||||
@ -6289,7 +6283,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
|||||||
Op1 = ConstantExpr::getBitCast(Op1C, Op0->getType());
|
Op1 = ConstantExpr::getBitCast(Op1C, Op0->getType());
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, cast the RHS right before the icmp
|
// Otherwise, cast the RHS right before the icmp
|
||||||
Op1 = InsertBitCastBefore(Op1, Op0->getType(), I);
|
Op1 = Builder->CreateBitCast(Op1, Op0->getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ICmpInst(I.getPredicate(), Op0, Op1);
|
return new ICmpInst(I.getPredicate(), Op0, Op1);
|
||||||
@ -7097,7 +7091,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
|
|||||||
RHSOp = RHSC->getOperand(0);
|
RHSOp = RHSC->getOperand(0);
|
||||||
// If the pointer types don't match, insert a bitcast.
|
// If the pointer types don't match, insert a bitcast.
|
||||||
if (LHSCIOp->getType() != RHSOp->getType())
|
if (LHSCIOp->getType() != RHSOp->getType())
|
||||||
RHSOp = InsertBitCastBefore(RHSOp, LHSCIOp->getType(), ICI);
|
RHSOp = Builder->CreateBitCast(RHSOp, LHSCIOp->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RHSOp)
|
if (RHSOp)
|
||||||
@ -9584,8 +9578,8 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
|
|||||||
SrcAlign = std::max(SrcAlign, CopyAlign);
|
SrcAlign = std::max(SrcAlign, CopyAlign);
|
||||||
DstAlign = std::max(DstAlign, CopyAlign);
|
DstAlign = std::max(DstAlign, CopyAlign);
|
||||||
|
|
||||||
Value *Src = InsertBitCastBefore(MI->getOperand(2), NewPtrTy, *MI);
|
Value *Src = Builder->CreateBitCast(MI->getOperand(2), NewPtrTy);
|
||||||
Value *Dest = InsertBitCastBefore(MI->getOperand(1), NewPtrTy, *MI);
|
Value *Dest = Builder->CreateBitCast(MI->getOperand(1), NewPtrTy);
|
||||||
Instruction *L = new LoadInst(Src, "tmp", false, SrcAlign);
|
Instruction *L = new LoadInst(Src, "tmp", false, SrcAlign);
|
||||||
InsertNewInstBefore(L, *MI);
|
InsertNewInstBefore(L, *MI);
|
||||||
InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI);
|
InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI);
|
||||||
@ -9619,7 +9613,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
|
|||||||
const Type *ITy = IntegerType::get(*Context, Len*8); // n=1 -> i8.
|
const Type *ITy = IntegerType::get(*Context, Len*8); // n=1 -> i8.
|
||||||
|
|
||||||
Value *Dest = MI->getDest();
|
Value *Dest = MI->getDest();
|
||||||
Dest = InsertBitCastBefore(Dest, PointerType::getUnqual(ITy), *MI);
|
Dest = Builder->CreateBitCast(Dest, PointerType::getUnqual(ITy));
|
||||||
|
|
||||||
// Alignment 0 is identity for alignment 1 for memset, but not store.
|
// Alignment 0 is identity for alignment 1 for memset, but not store.
|
||||||
if (Alignment == 0) Alignment = 1;
|
if (Alignment == 0) Alignment = 1;
|
||||||
@ -9720,9 +9714,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||||||
// Turn PPC lvx -> load if the pointer is known aligned.
|
// Turn PPC lvx -> load if the pointer is known aligned.
|
||||||
// Turn X86 loadups -> load if the pointer is known aligned.
|
// Turn X86 loadups -> load if the pointer is known aligned.
|
||||||
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
|
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
|
||||||
Value *Ptr = InsertBitCastBefore(II->getOperand(1),
|
Value *Ptr = Builder->CreateBitCast(II->getOperand(1),
|
||||||
PointerType::getUnqual(II->getType()),
|
PointerType::getUnqual(II->getType()));
|
||||||
CI);
|
|
||||||
return new LoadInst(Ptr);
|
return new LoadInst(Ptr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -9732,7 +9725,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||||||
if (GetOrEnforceKnownAlignment(II->getOperand(2), 16) >= 16) {
|
if (GetOrEnforceKnownAlignment(II->getOperand(2), 16) >= 16) {
|
||||||
const Type *OpPtrTy =
|
const Type *OpPtrTy =
|
||||||
PointerType::getUnqual(II->getOperand(1)->getType());
|
PointerType::getUnqual(II->getOperand(1)->getType());
|
||||||
Value *Ptr = InsertBitCastBefore(II->getOperand(2), OpPtrTy, CI);
|
Value *Ptr = Builder->CreateBitCast(II->getOperand(2), OpPtrTy);
|
||||||
return new StoreInst(II->getOperand(1), Ptr);
|
return new StoreInst(II->getOperand(1), Ptr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -9743,7 +9736,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||||||
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
|
if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
|
||||||
const Type *OpPtrTy =
|
const Type *OpPtrTy =
|
||||||
PointerType::getUnqual(II->getOperand(2)->getType());
|
PointerType::getUnqual(II->getOperand(2)->getType());
|
||||||
Value *Ptr = InsertBitCastBefore(II->getOperand(1), OpPtrTy, CI);
|
Value *Ptr = Builder->CreateBitCast(II->getOperand(1), OpPtrTy);
|
||||||
return new StoreInst(II->getOperand(2), Ptr);
|
return new StoreInst(II->getOperand(2), Ptr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -9780,8 +9773,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||||||
|
|
||||||
if (AllEltsOk) {
|
if (AllEltsOk) {
|
||||||
// Cast the input vectors to byte vectors.
|
// Cast the input vectors to byte vectors.
|
||||||
Value *Op0 =InsertBitCastBefore(II->getOperand(1),Mask->getType(),CI);
|
Value *Op0 = Builder->CreateBitCast(II->getOperand(1), Mask->getType());
|
||||||
Value *Op1 =InsertBitCastBefore(II->getOperand(2),Mask->getType(),CI);
|
Value *Op1 = Builder->CreateBitCast(II->getOperand(2), Mask->getType());
|
||||||
Value *Result = UndefValue::get(Op0->getType());
|
Value *Result = UndefValue::get(Op0->getType());
|
||||||
|
|
||||||
// Only extract each element once.
|
// Only extract each element once.
|
||||||
@ -12180,11 +12173,11 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
|
|||||||
EI.getName()+".rhs");
|
EI.getName()+".rhs");
|
||||||
return BinaryOperator::Create(BO->getOpcode(), newEI0, newEI1);
|
return BinaryOperator::Create(BO->getOpcode(), newEI0, newEI1);
|
||||||
}
|
}
|
||||||
} else if (isa<LoadInst>(I)) {
|
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
||||||
unsigned AS =
|
unsigned AS = LI->getPointerAddressSpace();
|
||||||
cast<PointerType>(I->getOperand(0)->getType())->getAddressSpace();
|
Value *Ptr = Builder->CreateBitCast(I->getOperand(0),
|
||||||
Value *Ptr = InsertBitCastBefore(I->getOperand(0),
|
PointerType::get(EI.getType(), AS),
|
||||||
PointerType::get(EI.getType(), AS),*I);
|
I->getOperand(0)->getName());
|
||||||
Value *GEP =
|
Value *GEP =
|
||||||
Builder->CreateGEP(Ptr, EI.getOperand(1), I->getName()+".gep");
|
Builder->CreateGEP(Ptr, EI.getOperand(1), I->getName()+".gep");
|
||||||
cast<GEPOperator>(GEP)->setIsInBounds(true);
|
cast<GEPOperator>(GEP)->setIsInBounds(true);
|
||||||
@ -12193,6 +12186,10 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
|
|||||||
|
|
||||||
// Make sure the Load goes before the load instruction in the source,
|
// Make sure the Load goes before the load instruction in the source,
|
||||||
// not wherever the extract happens to be.
|
// not wherever the extract happens to be.
|
||||||
|
if (Instruction *P = dyn_cast<Instruction>(Ptr))
|
||||||
|
P->moveBefore(I);
|
||||||
|
if (Instruction *G = dyn_cast<Instruction>(GEP))
|
||||||
|
G->moveBefore(I);
|
||||||
Load->moveBefore(I);
|
Load->moveBefore(I);
|
||||||
|
|
||||||
return ReplaceInstUsesWith(EI, Load);
|
return ReplaceInstUsesWith(EI, Load);
|
||||||
@ -12204,8 +12201,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
|
|||||||
return ReplaceInstUsesWith(EI, IE->getOperand(1));
|
return ReplaceInstUsesWith(EI, IE->getOperand(1));
|
||||||
// If the inserted and extracted elements are constants, they must not
|
// If the inserted and extracted elements are constants, they must not
|
||||||
// be the same value, extract from the pre-inserted value instead.
|
// be the same value, extract from the pre-inserted value instead.
|
||||||
if (isa<Constant>(IE->getOperand(2)) &&
|
if (isa<Constant>(IE->getOperand(2)) && isa<Constant>(EI.getOperand(1))) {
|
||||||
isa<Constant>(EI.getOperand(1))) {
|
|
||||||
Worklist.AddValue(EI.getOperand(0));
|
Worklist.AddValue(EI.getOperand(0));
|
||||||
EI.setOperand(0, IE->getOperand(0));
|
EI.setOperand(0, IE->getOperand(0));
|
||||||
return &EI;
|
return &EI;
|
||||||
@ -12228,7 +12224,8 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
|
|||||||
return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
|
return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
|
||||||
}
|
}
|
||||||
return ExtractElementInst::Create(Src,
|
return ExtractElementInst::Create(Src,
|
||||||
ConstantInt::get(Type::getInt32Ty(*Context), SrcIdx, false));
|
ConstantInt::get(Type::getInt32Ty(*Context), SrcIdx,
|
||||||
|
false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME: Canonicalize extractelement(bitcast) -> bitcast(extractelement)
|
// FIXME: Canonicalize extractelement(bitcast) -> bitcast(extractelement)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user