You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch applies the nsw (no signed wrap) flag to 64 add i32 instructions across the filter_screened_poisson IR function. All changes are localized to the BSplineEvaluationData class’s evaluation logic — specifically in centerValue, cornerValue, and OffsetToIndex methods — where integer additions feed into sign-extensions (sext i32 to i64) used for indexing.
The major changes are:
Addition overflow semantics tightened: Each modified add is now marked nsw, signaling that the operation is guaranteed not to overflow signed 32-bit integers. This enables LLVM optimizations (e.g., strength reduction, loop simplification, or elimination of redundant overflow checks) by allowing the optimizer to assume well-defined behavior under signed arithmetic.
Consistent pattern across B-spline index computations: The affected adds compute offset-based indices (e.g., %notmask.i.i.iXXX + %some_constant) used in multi-dimensional array or coefficient lookups. The constants (e.g., %65, %103, %945, %1621, etc.) are mostly small offsets or precomputed base indices — suggesting these additions model grid traversal or hierarchical spline evaluation (e.g., child node indexing in octree-like structures).
No change to control flow or data dependencies: All modifications are purely attribute additions to existing add instructions; no new instructions, branches, or operands are introduced. The sext and branching structure remain identical — confirming this is a semantic refinement, not a functional change.
Broad coverage across evaluator variants: Changes span both Evaluator and ChildEvaluator subroutines, indicating the optimization applies uniformly across different levels of the B-spline evaluation hierarchy — likely reflecting consistent invariants in the underlying mesh/point-cloud processing algorithm.
Likely result of improved range analysis or profile-guided optimization: The systematic application of nsw across dozens of similar patterns suggests either (a) a pass (e.g., SimplifyCFG, InstCombine, or LoopVectorize) has proven safe bounds for these adds, or (b) upstream C++ code was annotated (e.g., with __builtin_assume or llvm.assume) or compiled with -fwrapv-incompatible assumptions, enabling stricter IR inference.
In summary: This is a targeted, semantics-preserving optimization that strengthens integer overflow assumptions in B-spline index arithmetic — enabling downstream optimizations while preserving correctness under the established domain constraints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link: llvm/llvm-project#174355
Requested by: @nikic