mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
TransformUtils: Avoid getNodePtrUnchecked() in integer division, NFC
Stop relying on `getNodePtrUnchecked()` being useful on invalid iterators. This function is documented to be for internal use only, and the pointer type will eventually have to change to remove UB from ilist_iterator. Instead, check the iterator before it has been invalidated. llvm-svn: 261497
This commit is contained in:
parent
9a2563de7c
commit
37982bac02
@ -390,6 +390,8 @@ bool llvm::expandRemainder(BinaryOperator *Rem) {
|
|||||||
Value *Remainder = generateSignedRemainderCode(Rem->getOperand(0),
|
Value *Remainder = generateSignedRemainderCode(Rem->getOperand(0),
|
||||||
Rem->getOperand(1), Builder);
|
Rem->getOperand(1), Builder);
|
||||||
|
|
||||||
|
// Check whether this is the insert point while Rem is still valid.
|
||||||
|
bool IsInsertPoint = Rem->getIterator() == Builder.GetInsertPoint();
|
||||||
Rem->replaceAllUsesWith(Remainder);
|
Rem->replaceAllUsesWith(Remainder);
|
||||||
Rem->dropAllReferences();
|
Rem->dropAllReferences();
|
||||||
Rem->eraseFromParent();
|
Rem->eraseFromParent();
|
||||||
@ -397,7 +399,7 @@ bool llvm::expandRemainder(BinaryOperator *Rem) {
|
|||||||
// If we didn't actually generate an urem instruction, we're done
|
// If we didn't actually generate an urem instruction, we're done
|
||||||
// This happens for example if the input were constant. In this case the
|
// This happens for example if the input were constant. In this case the
|
||||||
// Builder insertion point was unchanged
|
// Builder insertion point was unchanged
|
||||||
if (Rem == Builder.GetInsertPoint().getNodePtrUnchecked())
|
if (IsInsertPoint)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
|
BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
|
||||||
@ -446,6 +448,9 @@ bool llvm::expandDivision(BinaryOperator *Div) {
|
|||||||
// Lower the code to unsigned division, and reset Div to point to the udiv.
|
// Lower the code to unsigned division, and reset Div to point to the udiv.
|
||||||
Value *Quotient = generateSignedDivisionCode(Div->getOperand(0),
|
Value *Quotient = generateSignedDivisionCode(Div->getOperand(0),
|
||||||
Div->getOperand(1), Builder);
|
Div->getOperand(1), Builder);
|
||||||
|
|
||||||
|
// Check whether this is the insert point while Div is still valid.
|
||||||
|
bool IsInsertPoint = Div->getIterator() == Builder.GetInsertPoint();
|
||||||
Div->replaceAllUsesWith(Quotient);
|
Div->replaceAllUsesWith(Quotient);
|
||||||
Div->dropAllReferences();
|
Div->dropAllReferences();
|
||||||
Div->eraseFromParent();
|
Div->eraseFromParent();
|
||||||
@ -453,7 +458,7 @@ bool llvm::expandDivision(BinaryOperator *Div) {
|
|||||||
// If we didn't actually generate an udiv instruction, we're done
|
// If we didn't actually generate an udiv instruction, we're done
|
||||||
// This happens for example if the input were constant. In this case the
|
// This happens for example if the input were constant. In this case the
|
||||||
// Builder insertion point was unchanged
|
// Builder insertion point was unchanged
|
||||||
if (Div == Builder.GetInsertPoint().getNodePtrUnchecked())
|
if (IsInsertPoint)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
|
BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user