Skip to content

intel/fs: Fix D to W conversion in opt_combine_constants

Ian Romanick requested to merge idr/mesa:review/fix-D-to-W-conversion into master

Found by GCC warning:

src/intel/compiler/brw_fs_combine_constants.cpp: In function ‘bool needs_negate(const fs_reg*, const imm*)’:
src/intel/compiler/brw_fs_combine_constants.cpp:306:34: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
       return ((reg->d & 0xffffu) < 0) != (imm->w < 0);

The result of the bit-and is a 32-bit value with the top bits all zero. This will never be < 0. Instead of masking off the bits, just cast to int16_t and let the compiler handle the actual conversion.

Fixes: e64be391 ("intel/compiler: generalize the combine constants pass")
Cc: Iago Toral Quiroga <> @itoral
Cc: Jason Ekstrand <> @jekstrand

Passes Intel CI. Since the incorrect code also passed, this just means we have inadequate test coverage. I'm open for suggestions to improve that. Perhaps a targeted unit test in Mesa?

Edited by Ian Romanick

Merge request reports