Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Added check for NUW #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,22 +502,29 @@ static Value *tryFactorization(InstCombiner::BuilderTy *Builder,
++NumFactor;
SimplifiedInst->takeName(&I);

// Check if we can add NSW flag to SimplifiedInst. If so, set NSW flag.
// TODO: Check for NUW.
// Check if we can add NSW/NUW flag to SimplifiedInst. If so, set NSW/NUW flag.
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(SimplifiedInst)) {
if (isa<OverflowingBinaryOperator>(SimplifiedInst)) {
bool HasNSW = false;
if (isa<OverflowingBinaryOperator>(&I))
bool HasNUW = false;
if (isa<OverflowingBinaryOperator>(&I)) {
HasNSW = I.hasNoSignedWrap();

HasNUW = I.hasNoUnsignedWrap();
}

if (BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS))
if (isa<OverflowingBinaryOperator>(Op0))
if (isa<OverflowingBinaryOperator>(Op0)) {
HasNSW &= Op0->hasNoSignedWrap();

HasNUW &= Op0->hasNoUnsignedWrap();
}

if (BinaryOperator *Op1 = dyn_cast<BinaryOperator>(RHS))
if (isa<OverflowingBinaryOperator>(Op1))
if (isa<OverflowingBinaryOperator>(Op1)) {
HasNSW &= Op1->hasNoSignedWrap();
hasNUW &= Op1->hasNoUnsignedWrap();
}
BO->setHasNoSignedWrap(HasNSW);
BO->setHasNoUnsignedWrap(HasNUW);
}
}
}
Expand Down