[llvm] [X86] Prevent NUW flag forwarding in ADD->SUB peephole (PR #201612)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 10:23:37 PDT 2026


hesam-oxe wrote:

@RKSimon @arsenm Understood — ditching it, and thank you both for the direct feedback.

To answer the question: yes, I'd like to have a go at the general mechanism within this release cycle. Where I'd start, incorporating arsenm's point about the marker granularity:

- The stopgap guarded individual X86 patterns; the real fix belongs at the single point where the matched node's flags are transferred onto the selected node, so that poison-generating flags (`nsw`/`nuw`) don't survive an opcode change by default. No per-pattern opt-out needed in the common case; flag transfer stays valid where the opcode is unchanged (operand reordering, register-class tightening).
- You're right that a pattern-level `let CopyPoisonFlags` is the wrong granularity — a pattern can have multiple input nodes and produce multiple output instructions, so "the pattern preserves flags" isn't even well-defined. If an escape hatch turns out to be necessary at all, it would have to be attached to the specific matched-opcode → selected-opcode pair, not the pattern; I'd first try to land the default-deny transfer with no escape hatch and see what actually breaks.
- Fallout control: run the full test suite and fix whatever depended on the old transfer — that's the real chunk of work, and the reason I won't promise a PR next week, but the mid-January window is realistic.

Closing this PR; the fresh one will reference it and #160217. Thanks again for the review and the design discussion — it genuinely changed the shape of what I'll build.

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


More information about the llvm-commits mailing list