[clang] [llvm] [IR] Add getelementptr nusw and nuw flags (PR #90824)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Thu May 2 18:10:14 PDT 2024


================
@@ -1699,8 +1701,12 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
         I = GetElementPtrInst::Create(BC->SrcElemTy, Ops[0],
                                       ArrayRef(Ops).drop_front(), "constexpr",
                                       InsertBB);
-        if (BC->Flags)
+        if (BC->Flags & (1 << bitc::GEP_INBOUNDS))
           cast<GetElementPtrInst>(I)->setIsInBounds();
+        if (BC->Flags & (1 << bitc::GEP_NUSW))
----------------
nikic wrote:

I think using `else if` would be correct here as `setIsInBounds` will also set nusw by itself, but keeping all cases separate seems cleaner?

Otherwise we'll have the following code here...
```
        if (BC->Flags & (1 << bitc::GEP_INBOUNDS))
          cast<GetElementPtrInst>(I)->setIsInBounds();
        else if (BC->Flags & (1 << bitc::GEP_NUSW))
          cast<GetElementPtrInst>(I)->setHasNoUnsignedSignedWrap();
        if (BC->Flags & (1 << bitc::GEP_NUW))
          cast<GetElementPtrInst>(I)->setHasNoUnsignedWrap();
```
...at which point it will probably need a comment to explain why there is only one `else if` there.

https://github.com/llvm/llvm-project/pull/90824


More information about the cfe-commits mailing list