[llvm] [SeparateConstOffsetFromGEP] Preserve inbounds flag based on ValueTracking and NUW (PR #130617)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 10 05:46:36 PDT 2025


================
@@ -811,6 +780,30 @@ Value *ConstantOffsetExtractor::removeConstOffset(unsigned ChainIndex) {
   return NewBO;
 }
 
+/// A helper function to check if reassociating through an entry in the user
+/// chain would invalidate the GEP's nuw flag.
+static bool allowsPreservingNUW(User *U) {
+  assert(isa<BinaryOperator>(U) || isa<CastInst>(U) || isa<ConstantInt>(U));
+  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(U)) {
+    // Binary operations needd to be effectively add nuw.
----------------
arsenm wrote:

```suggestion
    // Binary operations need to be effectively add nuw.
```

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


More information about the llvm-commits mailing list