Index: InstructionCombining.cpp =================================================================== --- InstructionCombining.cpp +++ InstructionCombining.cpp @@ -502,22 +502,27 @@ ++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(SimplifiedInst)) { if (isa(SimplifiedInst)) { bool HasNSW = false; - if (isa(&I)) + bool HasNUW = false; + if (isa(&I)){ HasNSW = I.hasNoSignedWrap(); - + HasNUW = I.hasNoUnsignedWrap(); + } if (BinaryOperator *Op0 = dyn_cast(LHS)) - if (isa(Op0)) + if (isa(Op0)){ HasNSW &= Op0->hasNoSignedWrap(); - + HasNUW &= Op0->hasNoUnsignedWrap(); + } if (BinaryOperator *Op1 = dyn_cast(RHS)) - if (isa(Op1)) + if (isa(Op1)){ HasNSW &= Op1->hasNoSignedWrap(); + HasNUW &= Op1->hasNoUnsignedWrap(); + } BO->setHasNoSignedWrap(HasNSW); + BO->setHasNoUnsignedWrap(HasNUW); } } }