llvm.org GIT mirror llvm / 5078f84
Rename hasNoUnsignedOverflow and hasNoSignedOverflow to hasNoUnsignedWrap and hasNoSignedWrap, for consistency with the nuw and nsw properties. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79539 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
11 changed file(s) with 41 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
425425 return cast(SE.getAddExpr(this, getStepRecurrence(SE)));
426426 }
427427
428 bool hasNoUnsignedOverflow() const { return SubclassData & (1 << 0); }
429 void setHasNoUnsignedOverflow(bool B) {
428 bool hasNoUnsignedWrap() const { return SubclassData & (1 << 0); }
429 void setHasNoUnsignedWrap(bool B) {
430430 SubclassData = (SubclassData & ~(1 << 0)) | (B << 0);
431431 }
432 bool hasNoSignedOverflow() const { return SubclassData & (1 << 1); }
433 void setHasNoSignedOverflow(bool B) {
432 bool hasNoSignedWrap() const { return SubclassData & (1 << 1); }
433 void setHasNoSignedWrap(bool B) {
434434 SubclassData = (SubclassData & ~(1 << 1)) | (B << 1);
435435 }
436436
179179 /// OverflowingBinaryOperatorOptionalFlags - Flags for serializing
180180 /// OverflowingBinaryOperator's SubclassOptionalData contents.
181181 enum OverflowingBinaryOperatorOptionalFlags {
182 OBO_NO_UNSIGNED_OVERFLOW = 0,
183 OBO_NO_SIGNED_OVERFLOW = 1
182 OBO_NO_UNSIGNED_WRAP = 0,
183 OBO_NO_SIGNED_WRAP = 1
184184 };
185185
186186 /// SDivOperatorOptionalFlags - Flags for serializing SDivOperator's
200200 static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
201201 const Twine &Name = "") {
202202 BinaryOperator *BO = CreateAdd(V1, V2, Name);
203 cast(BO)->setHasNoSignedOverflow(true);
203 cast(BO)->setHasNoSignedWrap(true);
204204 return BO;
205205 }
206206 static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
207207 const Twine &Name, BasicBlock *BB) {
208208 BinaryOperator *BO = CreateAdd(V1, V2, Name, BB);
209 cast(BO)->setHasNoSignedOverflow(true);
209 cast(BO)->setHasNoSignedWrap(true);
210210 return BO;
211211 }
212212 static BinaryOperator *CreateNSWAdd(Value *V1, Value *V2,
213213 const Twine &Name, Instruction *I) {
214214 BinaryOperator *BO = CreateAdd(V1, V2, Name, I);
215 cast(BO)->setHasNoSignedOverflow(true);
215 cast(BO)->setHasNoSignedWrap(true);
216216 return BO;
217217 }
218218
6868 class OverflowingBinaryOperator : public Operator {
6969 ~OverflowingBinaryOperator(); // do not implement
7070 public:
71 /// hasNoUnsignedOverflow - Test whether this operation is known to never
72 /// undergo unsigned overflow.
73 bool hasNoUnsignedOverflow() const {
71 /// hasNoUnsignedWrap - Test whether this operation is known to never
72 /// undergo unsigned overflow, aka the nuw property.
73 bool hasNoUnsignedWrap() const {
7474 return SubclassOptionalData & (1 << 0);
7575 }
76 void setHasNoUnsignedOverflow(bool B) {
76 void setHasNoUnsignedWrap(bool B) {
7777 SubclassOptionalData = (SubclassOptionalData & ~(1 << 0)) | (B << 0);
7878 }
7979
80 /// hasNoSignedOverflow - Test whether this operation is known to never
81 /// undergo signed overflow.
82 bool hasNoSignedOverflow() const {
80 /// hasNoSignedWrap - Test whether this operation is known to never
81 /// undergo signed overflow, aka the nsw property.
82 bool hasNoSignedWrap() const {
8383 return SubclassOptionalData & (1 << 1);
8484 }
85 void setHasNoSignedOverflow(bool B) {
85 void setHasNoSignedWrap(bool B) {
8686 SubclassOptionalData = (SubclassOptionalData & ~(1 << 1)) | (B << 1);
8787 }
8888
794794
795795 // If we have special knowledge that this addrec won't overflow,
796796 // we don't need to do any further analysis.
797 if (AR->hasNoUnsignedOverflow())
797 if (AR->hasNoUnsignedWrap())
798798 return getAddRecExpr(getZeroExtendExpr(Start, Ty),
799799 getZeroExtendExpr(Step, Ty),
800800 L);
933933
934934 // If we have special knowledge that this addrec won't overflow,
935935 // we don't need to do any further analysis.
936 if (AR->hasNoSignedOverflow())
936 if (AR->hasNoSignedWrap())
937937 return getAddRecExpr(getSignExtendExpr(Start, Ty),
938938 getSignExtendExpr(Step, Ty),
939939 L);
24962496 getSCEV(OBO->getOperand(1)) ==
24972497 PHISCEV->getStepRecurrence(*this)) {
24982498 const SCEVAddRecExpr *PostInc = PHISCEV->getPostIncExpr(*this);
2499 if (OBO->hasNoUnsignedOverflow()) {
2499 if (OBO->hasNoUnsignedWrap()) {
25002500 const_cast(PHISCEV)
2501 ->setHasNoUnsignedOverflow(true);
2501 ->setHasNoUnsignedWrap(true);
25022502 const_cast(PostInc)
2503 ->setHasNoUnsignedOverflow(true);
2503 ->setHasNoUnsignedWrap(true);
25042504 }
2505 if (OBO->hasNoSignedOverflow()) {
2505 if (OBO->hasNoSignedWrap()) {
25062506 const_cast(PHISCEV)
2507 ->setHasNoSignedOverflow(true);
2507 ->setHasNoSignedWrap(true);
25082508 const_cast(PostInc)
2509 ->setHasNoSignedOverflow(true);
2509 ->setHasNoSignedWrap(true);
25102510 }
25112511 }
25122512
20812081 return Error(ID.Loc,"constexpr requires integer, fp, or vector operands");
20822082 Constant *C = ConstantExpr::get(Opc, Val0, Val1);
20832083 if (NUW)
2084 cast(C)->setHasNoUnsignedOverflow(true);
2084 cast(C)->setHasNoUnsignedWrap(true);
20852085 if (NSW)
2086 cast(C)->setHasNoSignedOverflow(true);
2086 cast(C)->setHasNoSignedWrap(true);
20872087 if (Exact)
20882088 cast(C)->setIsExact(true);
20892089 ID.ConstantVal = C;
26642664 return Error(ModifierLoc, "nsw only applies to integer operations");
26652665 }
26662666 if (NUW)
2667 cast(Inst)->setHasNoUnsignedOverflow(true);
2667 cast(Inst)->setHasNoUnsignedWrap(true);
26682668 if (NSW)
2669 cast(Inst)->setHasNoSignedOverflow(true);
2669 cast(Inst)->setHasNoSignedWrap(true);
26702670 }
26712671 return Result;
26722672 }
882882 static void SetOptimizationFlags(Value *V, uint64_t Flags) {
883883 if (OverflowingBinaryOperator *OBO =
884884 dyn_cast(V)) {
885 if (Flags & (1 << bitc::OBO_NO_SIGNED_OVERFLOW))
886 OBO->setHasNoSignedOverflow(true);
887 if (Flags & (1 << bitc::OBO_NO_UNSIGNED_OVERFLOW))
888 OBO->setHasNoUnsignedOverflow(true);
885 if (Flags & (1 << bitc::OBO_NO_SIGNED_WRAP))
886 OBO->setHasNoSignedWrap(true);
887 if (Flags & (1 << bitc::OBO_NO_UNSIGNED_WRAP))
888 OBO->setHasNoUnsignedWrap(true);
889889 } else if (SDivOperator *Div = dyn_cast(V)) {
890890 if (Flags & (1 << bitc::SDIV_EXACT))
891891 Div->setIsExact(true);
460460
461461 if (const OverflowingBinaryOperator *OBO =
462462 dyn_cast(V)) {
463 if (OBO->hasNoSignedOverflow())
464 Flags |= 1 << bitc::OBO_NO_SIGNED_OVERFLOW;
465 if (OBO->hasNoUnsignedOverflow())
466 Flags |= 1 << bitc::OBO_NO_UNSIGNED_OVERFLOW;
463 if (OBO->hasNoSignedWrap())
464 Flags |= 1 << bitc::OBO_NO_SIGNED_WRAP;
465 if (OBO->hasNoUnsignedWrap())
466 Flags |= 1 << bitc::OBO_NO_UNSIGNED_WRAP;
467467 } else if (const SDivOperator *Div = dyn_cast(V)) {
468468 if (Div->isExact())
469469 Flags |= 1 << bitc::SDIV_EXACT;
30833083 if (SubOperator *Sub = dyn_cast(Op0))
30843084 if (isa(Sub->getOperand(0)) &&
30853085 cast(Sub->getOperand(0))->isNullValue() &&
3086 Sub->hasNoSignedOverflow())
3086 Sub->hasNoSignedWrap())
30873087 return BinaryOperator::CreateSDiv(Sub->getOperand(1),
30883088 ConstantExpr::getNeg(RHS));
30893089 }
894894 static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
895895 if (const OverflowingBinaryOperator *OBO =
896896 dyn_cast(U)) {
897 if (OBO->hasNoUnsignedOverflow())
897 if (OBO->hasNoUnsignedWrap())
898898 Out << " nuw";
899 if (OBO->hasNoSignedOverflow())
899 if (OBO->hasNoSignedWrap())
900900 Out << " nsw";
901901 } else if (const SDivOperator *Div = dyn_cast(U)) {
902902 if (Div->isExact())
633633 // Set nsw attribute, assuming constant folding didn't eliminate the
634634 // Add.
635635 if (AddOperator *Add = dyn_cast(C))
636 Add->setHasNoSignedOverflow(true);
636 Add->setHasNoSignedWrap(true);
637637 return C;
638638 }
639639