]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
s390x: Fix negative signed immediate operands in code gen
authorAndreas Arnez <arnez@linux.ibm.com>
Wed, 18 Mar 2026 17:27:44 +0000 (18:27 +0100)
committerAndreas Arnez <arnez@linux.ibm.com>
Wed, 18 Mar 2026 18:29:01 +0000 (19:29 +0100)
The helper functions that check whether an integer constant fits into a
16-bit or 32-bit signed immediate operand always return false for negative
values.  This prevents the use of negative immediate operands altogether
and may lead to unnecessarily clumsy code being emitted, such as

  v-add    %r8,-160               8 bytes
  iihf      %r0,4294967295
  iilf      %r0,4294967136
  agr       %r8,%r0

instead of

  v-add    %r8,-160               8 bytes
  aghi      %r8,-160

This behavior is a regression; it was introduced by

  commit #0282c1cfc9015b69d09 -- s390: Tweak a few helper functions.

However, the previous code was perhaps a bit obscure.  So instead of
reverting to that, use simple checks like "val + 0x8000 <= 0xFFFF",
exploiting standard C integer semantics.

VEX/priv/host_s390_defs.c

index 28b66ef5c7c548f2794faf54e6a3d946965d137a..8ff386cc4ad5ae9e238f6c65e4d13c56d3b99be3 100644 (file)
@@ -4176,21 +4176,21 @@ s390_emit_RISBG(UChar *p, UChar r1, UChar r2, UChar i3, Char i4, UChar i5)
 static __inline__ Bool
 uint_fits_signed_16bit(UInt val)
 {
-   return val <= 0x7FFFu;
+   return val + 0x8000 <= 0xFFFF;
 }
 
 
 static __inline__ Bool
 ulong_fits_signed_16bit(ULong val)
 {
-   return val <= 0x7FFFu;
+   return val + 0x8000 <= 0xFFFF;
 }
 
 
 static __inline__ Bool
 ulong_fits_signed_32bit(ULong val)
 {
-   return val <= 0x7FFFFFFFu;
+   return val + 0x80000000 <= 0xFFFFFFFF;
 }