Skip to content

ac/nir/ngg: fix nogs culling with nuw add

Qiang Yu requested to merge yuq825/mesa:topic/fix-ac-ngg-nuw into main

We should not use "nuw" here as negative add possitive may wrap around (negative is 0xffffff??).

This problem can be observed with LLVM15 (I can't see when LLVM14):

  %.neg = mul nsw i32 %31, -4
  %163 = add nuw nsw i32 %.neg, 16
  %164 = lshr i32 257, %.neg
  %165 = lshr i32 %164, %163

LLVM just assume %.neg is possitive, so pre-shift 0x01010101 by 16. This get wrong value because we can't get back the shifted bits with a negative shift right.

Fixes: 75dbb404 ("ac/nir: Remove byte permute from prefix sum of the repack sequence.")

Edited by Qiang Yu

Merge request reports