diff options
| author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-03-31 05:14:26 +0000 |
|---|---|---|
| committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-03-31 05:14:26 +0000 |
| commit | e12c0e515953c0ddb1e4a29c4559e2fcb0e3475a (patch) | |
| tree | ded5579bad705f922280779f1677720dc7ac0107 /llvm/lib | |
| parent | 118d919a6a47867c553842a815f304f0477509be (diff) | |
| download | bcm5719-llvm-e12c0e515953c0ddb1e4a29c4559e2fcb0e3475a.tar.gz bcm5719-llvm-e12c0e515953c0ddb1e4a29c4559e2fcb0e3475a.zip | |
[SCEV] Track NoWrap properties using MatchBinaryOp, NFC
This way once we teach MatchBinaryOp to map more things into arithmetic,
the non-wrapping add recurrence construction would understand it too.
Right now MatchBinaryOp still only understands arithmetic, so this is
solely a code-reorganization change.
llvm-svn: 264994
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7d383835fa4..402a1b7c4ea 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -3806,6 +3806,8 @@ struct BinaryOp { unsigned Opcode; Value *LHS; Value *RHS; + bool IsNSW; + bool IsNUW; /// Op is set if this BinaryOp corresponds to a concrete LLVM instruction or /// constant expression. @@ -3813,10 +3815,17 @@ struct BinaryOp { explicit BinaryOp(Operator *Op) : Opcode(Op->getOpcode()), LHS(Op->getOperand(0)), RHS(Op->getOperand(1)), - Op(Op) {} + IsNSW(false), IsNUW(false), Op(Op) { + if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(Op)) { + IsNSW = OBO->hasNoSignedWrap(); + IsNUW = OBO->hasNoUnsignedWrap(); + } + } - explicit BinaryOp(unsigned Opcode, Value *LHS, Value *RHS) - : Opcode(Opcode), LHS(LHS), RHS(RHS), Op(nullptr) {} + explicit BinaryOp(unsigned Opcode, Value *LHS, Value *RHS, bool IsNSW = false, + bool IsNUW = false) + : Opcode(Opcode), LHS(LHS), RHS(RHS), IsNSW(IsNSW), IsNUW(IsNUW), + Op(nullptr) {} }; } @@ -3944,11 +3953,11 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) { // If the increment doesn't overflow, then neither the addrec nor // the post-increment will overflow. - if (const AddOperator *OBO = dyn_cast<AddOperator>(BEValueV)) { - if (OBO->getOperand(0) == PN) { - if (OBO->hasNoUnsignedWrap()) + if (auto BO = MatchBinaryOp(BEValueV)) { + if (BO->Opcode == Instruction::Add && BO->LHS == PN) { + if (BO->IsNUW) Flags = setFlags(Flags, SCEV::FlagNUW); - if (OBO->hasNoSignedWrap()) + if (BO->IsNSW) Flags = setFlags(Flags, SCEV::FlagNSW); } } else if (GEPOperator *GEP = dyn_cast<GEPOperator>(BEValueV)) { |

