File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -609,10 +609,12 @@ Expr lossless_negate(const Expr &x) {
609609 } else if (const FloatImm *f = x.as <FloatImm>()) {
610610 return FloatImm::make (f->type , -f->value );
611611 } else if (const Cast *c = x.as <Cast>()) {
612- // Only safe to negate through a cast when the inner type is signed .
612+ // Only safe to negate through a cast when the inner type is not unsigned .
613613 // For unsigned inner types, negation wraps modularly (e.g., -uint8(65)
614614 // = uint8(191)), so cast(outer, -inner) != -cast(outer, inner).
615- if (c->value .type ().is_int ()) {
615+ // Signed integers and floats are fine: signed negation is checked for
616+ // overflow below via lossless_cast, and float negation is exact.
617+ if (!c->value .type ().is_uint ()) {
616618 Expr value = lossless_negate (c->value );
617619 if (value.defined ()) {
618620 // This logic is only sound if we know the cast can't overflow.
You can’t perform that action at this time.
0 commit comments