diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c
index 807adfef54969a3df013e8f4bf3ccdd9fdabb847..5adc3216c98d500e556743284776223287a55771 100644
--- a/src/core/lib/transport/static_metadata.c
+++ b/src/core/lib/transport/static_metadata.c
@@ -440,7 +440,12 @@ static uint32_t elems_phash(uint32_t i) {
   i -= 42;
   uint32_t x = i % 96;
   uint32_t y = i / 96;
-  return y < GPR_ARRAY_SIZE(elems_r) ? x + (uint32_t)elems_r[y] : 0;
+  uint32_t h = x;
+  if (y < GPR_ARRAY_SIZE(elems_r)) {
+    uint32_t delta = (uint32_t)elems_r[y];
+    h += delta;
+  }
+  return h;
 }
 
 static const uint16_t elem_keys[] = {
diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py
index 1a2911cd04c6fcfe0a7901118292a7b8252dae52..0374cf75a1a17c548b950d6f71bba83c71fd5572 100755
--- a/tools/codegen/core/gen_static_metadata.py
+++ b/tools/codegen/core/gen_static_metadata.py
@@ -424,7 +424,12 @@ static uint32_t %(name)s_phash(uint32_t i) {
   i %(offset_sign)s= %(offset)d;
   uint32_t x = i %% %(t)d;
   uint32_t y = i / %(t)d;
-  return y < GPR_ARRAY_SIZE(%(name)s_r) ? x + (uint32_t)%(name)s_r[y] : 0;
+  uint32_t h = x;
+  if (y < GPR_ARRAY_SIZE(%(name)s_r)) {
+    uint32_t delta = (uint32_t)%(name)s_r[y];
+    h += delta;
+  }
+  return h;
 }
     """ % {
       'name': name,