[clang] [CIR] Add MinusOp::fold tests for poison and nsw (PR #240820)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 1 14:53:01 PST 2026
================
@@ -3636,6 +3636,8 @@ OpFoldResult cir::MinusOp::fold(FoldAdaptor adaptor) {
if (auto intAttr =
mlir::dyn_cast_if_present<cir::IntAttr>(adaptor.getInput())) {
APInt val = intAttr.getValue();
+ if (getNoSignedWrap() && val.isMinSignedValue())
----------------
andykaylor wrote:
I agree, we shouldn't be folding this to poison. The semantics literally say that the result is poison if signed wrap occurs, but LLVM's constant folder won't do that. Semantically, because the return value is poison, we can substitute literally any other value, and in this case we get best compiler behavior (as defined by matching user expectations) by substituting the result with the signed wrap. The UB sanitizer should flag cases like this, but we don't want to enforce the poison.
https://github.com/llvm/llvm-project/pull/240820
More information about the cfe-commits
mailing list