[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:35 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));
----------------
arsenm wrote:

A ConstantInt can't be a user. I'd also remove this assert, and turn it into a conservatively correct return false at the end. It confusingly partially overlaps with the conditions you actually check for here. If you want the assert, put the unreachable at the end here 

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


More information about the llvm-commits mailing list