diff options
author | Nikita Popov <npopov@redhat.com> | 2024-05-27 16:05:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-27 16:05:17 +0200 |
commit | 8cdecd4d3aedea7bc5f27d1f69da216100cb2815 (patch) | |
tree | fb5b5a1d15766c4187abfabc4a6248c18bf7f1a3 /llvm/lib/IR/Constants.cpp | |
parent | 49b760ff2c7da60f4308708f56688ca99874605f (diff) | |
download | llvm-8cdecd4d3aedea7bc5f27d1f69da216100cb2815.zip llvm-8cdecd4d3aedea7bc5f27d1f69da216100cb2815.tar.gz llvm-8cdecd4d3aedea7bc5f27d1f69da216100cb2815.tar.bz2 |
[IR] Add getelementptr nusw and nuw flags (#90824)
This implements the `nusw` and `nuw` flags for `getelementptr` as
proposed at
https://discourse.llvm.org/t/rfc-add-nusw-and-nuw-flags-for-getelementptr/78672.
The three possible flags are encapsulated in the new `GEPNoWrapFlags`
class. Currently this class has a ctor from bool, interpreted as the
InBounds flag. This ctor should be removed in the future, as code gets
migrated to handle all flags.
There are a few places annotated with `TODO(gep_nowrap)`, where I've had
to touch code but opted to not infer or precisely preserve the new
flags, so as to keep this as NFC as possible and make sure any changes
of that kind get test coverage when they are made.
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index db442c5..cfb89d5 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1568,7 +1568,7 @@ Constant *ConstantExpr::getWithOperands(ArrayRef<Constant *> Ops, Type *Ty, assert(SrcTy || (Ops[0]->getType() == getOperand(0)->getType())); return ConstantExpr::getGetElementPtr( SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.slice(1), - GEPO->isInBounds(), GEPO->getInRange(), OnlyIfReducedTy); + GEPO->getNoWrapFlags(), GEPO->getInRange(), OnlyIfReducedTy); } case Instruction::ICmp: case Instruction::FCmp: @@ -2348,13 +2348,15 @@ Constant *ConstantExpr::getCompare(unsigned short Predicate, Constant *C1, } Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, - ArrayRef<Value *> Idxs, bool InBounds, + ArrayRef<Value *> Idxs, + GEPNoWrapFlags NW, std::optional<ConstantRange> InRange, Type *OnlyIfReducedTy) { assert(Ty && "Must specify element type"); assert(isSupportedGetElementPtr(Ty) && "Element type is unsupported!"); - if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InBounds, InRange, Idxs)) + if (Constant *FC = + ConstantFoldGetElementPtr(Ty, C, NW.isInBounds(), InRange, Idxs)) return FC; // Fold a few common cases. assert(GetElementPtrInst::getIndexedType(Ty, Idxs) && "GEP indices invalid!"); @@ -2390,10 +2392,8 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, ArgVec.push_back(Idx); } - unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0; const ConstantExprKeyType Key(Instruction::GetElementPtr, ArgVec, 0, - SubClassOptionalData, std::nullopt, Ty, - InRange); + NW.getRaw(), std::nullopt, Ty, InRange); LLVMContextImpl *pImpl = C->getContext().pImpl; return pImpl->ExprConstants.getOrCreate(ReqTy, Key); |