Simplify resource_table texture checks

When checking if the texture kind is filterable in the resource_table
transform we don't have to check against all filterable textures, we
only have to check to see if the resource table texture is the
filterable version of the texture type used in the call.

We would have already validated that the type returned from getResource
is correct for the texture call, so the type must be correct based on
prior checks.

Bug: 479179409
Change-Id: I3b3050a1e1c3a8f6f92d9fcd5ce86040f13b6dd3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/310355
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/ir/transform/resource_table.cc b/src/tint/lang/core/ir/transform/resource_table.cc
index 259eaf9..da36313 100644
--- a/src/tint/lang/core/ir/transform/resource_table.cc
+++ b/src/tint/lang/core/ir/transform/resource_table.cc
@@ -34,6 +34,7 @@
 #include "src/tint/lang/core/ir/var.h"
 #include "src/tint/lang/core/type/manager.h"
 #include "src/tint/lang/core/type/resource_type.h"
+#include "src/tint/lang/core/type/sampled_texture.h"
 
 namespace tint::core::ir::transform {
 namespace {
@@ -241,19 +242,17 @@
                         case core::BuiltinFn::kTextureSampleGrad:
                         case core::BuiltinFn::kTextureSampleLevel:
                         case core::BuiltinFn::kTextureSampleBaseClampToEdge: {
+                            Info call_info{
+                                .binding_type = binding_type,
+                                .slot_idx = idx,
+                                .operand_idx = usage.operand_index,
+                            };
+
                             auto& info = sampled_call_replacements.GetOrAddZeroEntry(call);
                             if (binding_type->Is<core::type::Texture>()) {
-                                info.value.texture = {
-                                    .binding_type = binding_type,
-                                    .slot_idx = idx,
-                                    .operand_idx = usage.operand_index,
-                                };
+                                info.value.texture = call_info;
                             } else {
-                                info.value.sampler = {
-                                    .binding_type = binding_type,
-                                    .slot_idx = idx,
-                                    .operand_idx = usage.operand_index,
-                                };
+                                info.value.sampler = call_info;
                             }
                             break;
                         }
@@ -364,35 +363,23 @@
         return kind;
     }
 
-    ir::InstructionResult* ConstructTextureFilterableCheck(ir::Value* texture_kind) {
-        size_t idx = 0;
-        const std::span<const ResourceType> filterable_types = core::type::FilterableResources();
-
-        ir::Binary* chk = b.Equal(texture_kind, u32(filterable_types[idx++]));
-        ir::If* t = b.If(chk);
-        ir::InstructionResult* tex_res = b.InstructionResult(ty.bool_());
-        t->SetResult(tex_res);
-
-        // The texture is filterable, so we can use the sampler
-        b.Append(t->True(), [&] { b.ExitIf(t, true); });
-
-        for (; idx < filterable_types.size(); ++idx) {
-            b.Append(t->False(), [&] {
-                core::ir::Binary* sub_chk = b.Equal(texture_kind, u32(filterable_types[idx]));
-                core::ir::If* sub_if = b.If(sub_chk);
-                core::ir::InstructionResult* r = b.InstructionResult(ty.bool_());
-                sub_if->SetResult(r);
-
-                // The texture is filterable, so we can use the sampler
-                b.Append(sub_if->True(), [&] { b.ExitIf(sub_if, true); });
-                b.ExitIf(t, r);
-
-                t = sub_if;
-            });
+    ir::Value* ConstructTextureFilterableCheck(const type::Type* tex_ty, ir::Value* texture_kind) {
+        const type::SampledTexture* samp_ty = tex_ty->As<type::SampledTexture>();
+        // Only sampled texture types can be filterable
+        if (!samp_ty) {
+            return b.Constant(false);
         }
-        // Texture is not filterable, return false
-        b.Append(t->False(), [&] { b.ExitIf(t, false); });
-        return tex_res;
+        // Only floating point sampled textures can be filterable
+        if (samp_ty->Type()->IsAnyOf<type::I32, type::U32>()) {
+            return b.Constant(false);
+        }
+
+        ResourceType res_type = core::type::DefaultResourceTypeFor(tex_ty);
+        if (texture_kind->Is<ir::Constant>()) {
+            uint32_t val = texture_kind->As<ir::Constant>()->Value()->ValueAs<uint32_t>();
+            return b.Constant(val == uint32_t(res_type));
+        }
+        return b.Equal(texture_kind, u32(res_type))->Result();
     }
 
     ir::Instruction* GetResource(ir::Value* idx, const type::Type* binding_type) {
@@ -459,6 +446,8 @@
             return;
         }
 
+        ir::Value* tex = call->Args()[texture_operand_idx];
+
         // Validate that the sampler/texture pair work together
         b.InsertBefore(call, [&] {
             core::ir::Value* samp_res = nullptr;
@@ -475,14 +464,14 @@
 
                 // If the sampler is filtering
                 b.Append(samp_if->True(), [&] {
-                    ir::InstructionResult* tex_res = ConstructTextureFilterableCheck(texture_kind);
+                    ir::Value* tex_res = ConstructTextureFilterableCheck(tex->Type(), texture_kind);
                     b.ExitIf(samp_if, tex_res);
                 });
 
                 // Sampler != filtering, so use_sampler is true
                 b.Append(samp_if->False(), [&] { b.ExitIf(samp_if, true); });
             } else {
-                samp_res = ConstructTextureFilterableCheck(texture_kind);
+                samp_res = ConstructTextureFilterableCheck(tex->Type(), texture_kind);
             }
 
             const core::type::Type* result_ty = call->Result()->Type();
diff --git a/src/tint/lang/core/ir/transform/resource_table_test.cc b/src/tint/lang/core/ir/transform/resource_table_test.cc
index d1c56b6..dc571bc 100644
--- a/src/tint/lang/core/ir/transform/resource_table_test.cc
+++ b/src/tint/lang/core/ir/transform/resource_table_test.cc
@@ -581,79 +581,26 @@
     %45:bool = eq %sampler_kind, 40u
     %use_sampler:bool = if %45 [t: $B15, f: $B16] {  # if_7
       $B15: {  # true
-        %47:bool = eq %texture_kind, 1u
-        %48:bool = if %47 [t: $B17, f: $B18] {  # if_8
-          $B17: {  # true
-            exit_if true  # if_8
-          }
-          $B18: {  # false
-            %49:bool = eq %texture_kind, 6u
-            %50:bool = if %49 [t: $B19, f: $B20] {  # if_9
-              $B19: {  # true
-                exit_if true  # if_9
-              }
-              $B20: {  # false
-                %51:bool = eq %texture_kind, 11u
-                %52:bool = if %51 [t: $B21, f: $B22] {  # if_10
-                  $B21: {  # true
-                    exit_if true  # if_10
-                  }
-                  $B22: {  # false
-                    %53:bool = eq %texture_kind, 16u
-                    %54:bool = if %53 [t: $B23, f: $B24] {  # if_11
-                      $B23: {  # true
-                        exit_if true  # if_11
-                      }
-                      $B24: {  # false
-                        %55:bool = eq %texture_kind, 21u
-                        %56:bool = if %55 [t: $B25, f: $B26] {  # if_12
-                          $B25: {  # true
-                            exit_if true  # if_12
-                          }
-                          $B26: {  # false
-                            %57:bool = eq %texture_kind, 26u
-                            %58:bool = if %57 [t: $B27, f: $B28] {  # if_13
-                              $B27: {  # true
-                                exit_if true  # if_13
-                              }
-                              $B28: {  # false
-                                exit_if false  # if_13
-                              }
-                            }
-                            exit_if %58  # if_12
-                          }
-                        }
-                        exit_if %56  # if_11
-                      }
-                    }
-                    exit_if %54  # if_10
-                  }
-                }
-                exit_if %52  # if_9
-              }
-            }
-            exit_if %50  # if_8
-          }
-        }
-        exit_if %48  # if_7
+        %47:bool = eq %texture_kind, 6u
+        exit_if %47  # if_7
       }
       $B16: {  # false
         exit_if true  # if_7
       }
     }
-    %59:vec4<f32> = if %use_sampler [t: $B29, f: $B30] {  # if_14
-      $B29: {  # true
-        %60:vec4<f32> = textureSample %25, %44, vec2<f32>(0.0f)
-        exit_if %60  # if_14
+    %48:vec4<f32> = if %use_sampler [t: $B17, f: $B18] {  # if_8
+      $B17: {  # true
+        %49:vec4<f32> = textureSample %25, %44, vec2<f32>(0.0f)
+        exit_if %49  # if_8
       }
-      $B30: {  # false
-        %61:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
-        %62:u32 = load %61
-        %63:u32 = add 5u, %62
-        %64:ptr<handle, sampler, read> = access %4, %63
-        %65:sampler = load %64
-        %66:vec4<f32> = textureSample %25, %65, vec2<f32>(0.0f)
-        exit_if %66  # if_14
+      $B18: {  # false
+        %50:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
+        %51:u32 = load %50
+        %52:u32 = add 5u, %51
+        %53:ptr<handle, sampler, read> = access %4, %52
+        %54:sampler = load %53
+        %55:vec4<f32> = textureSample %25, %54, vec2<f32>(0.0f)
+        exit_if %55  # if_8
       }
     }
     ret
@@ -774,73 +721,20 @@
     }
     %26:ptr<handle, texture_2d<f32>, read> = access %2, %22
     %27:texture_2d<f32> = load %26
-    %28:bool = eq %texture_kind, 1u
-    %29:bool = if %28 [t: $B9, f: $B10] {  # if_4
+    %28:bool = eq %texture_kind, 6u
+    %29:vec4<f32> = if %28 [t: $B9, f: $B10] {  # if_4
       $B9: {  # true
-        exit_if true  # if_4
+        %30:vec4<f32> = textureSample %27, %8, vec2<f32>(0.0f)
+        exit_if %30  # if_4
       }
       $B10: {  # false
-        %30:bool = eq %texture_kind, 6u
-        %31:bool = if %30 [t: $B11, f: $B12] {  # if_5
-          $B11: {  # true
-            exit_if true  # if_5
-          }
-          $B12: {  # false
-            %32:bool = eq %texture_kind, 11u
-            %33:bool = if %32 [t: $B13, f: $B14] {  # if_6
-              $B13: {  # true
-                exit_if true  # if_6
-              }
-              $B14: {  # false
-                %34:bool = eq %texture_kind, 16u
-                %35:bool = if %34 [t: $B15, f: $B16] {  # if_7
-                  $B15: {  # true
-                    exit_if true  # if_7
-                  }
-                  $B16: {  # false
-                    %36:bool = eq %texture_kind, 21u
-                    %37:bool = if %36 [t: $B17, f: $B18] {  # if_8
-                      $B17: {  # true
-                        exit_if true  # if_8
-                      }
-                      $B18: {  # false
-                        %38:bool = eq %texture_kind, 26u
-                        %39:bool = if %38 [t: $B19, f: $B20] {  # if_9
-                          $B19: {  # true
-                            exit_if true  # if_9
-                          }
-                          $B20: {  # false
-                            exit_if false  # if_9
-                          }
-                        }
-                        exit_if %39  # if_8
-                      }
-                    }
-                    exit_if %37  # if_7
-                  }
-                }
-                exit_if %35  # if_6
-              }
-            }
-            exit_if %33  # if_5
-          }
-        }
-        exit_if %31  # if_4
-      }
-    }
-    %40:vec4<f32> = if %29 [t: $B21, f: $B22] {  # if_10
-      $B21: {  # true
-        %41:vec4<f32> = textureSample %27, %8, vec2<f32>(0.0f)
-        exit_if %41  # if_10
-      }
-      $B22: {  # false
-        %42:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
-        %43:u32 = load %42
-        %44:u32 = add 5u, %43
-        %45:ptr<handle, sampler, read> = access %5, %44
-        %46:sampler = load %45
-        %47:vec4<f32> = textureSample %27, %46, vec2<f32>(0.0f)
-        exit_if %47  # if_10
+        %31:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
+        %32:u32 = load %31
+        %33:u32 = add 5u, %32
+        %34:ptr<handle, sampler, read> = access %5, %33
+        %35:sampler = load %34
+        %36:vec4<f32> = textureSample %27, %35, vec2<f32>(0.0f)
+        exit_if %36  # if_4
       }
     }
     ret
@@ -1090,79 +984,25 @@
     %28:bool = eq %sampler_kind, 40u
     %use_sampler:bool = if %28 [t: $B9, f: $B10] {  # if_4
       $B9: {  # true
-        %30:bool = eq 6u, 1u
-        %31:bool = if %30 [t: $B11, f: $B12] {  # if_5
-          $B11: {  # true
-            exit_if true  # if_5
-          }
-          $B12: {  # false
-            %32:bool = eq 6u, 6u
-            %33:bool = if %32 [t: $B13, f: $B14] {  # if_6
-              $B13: {  # true
-                exit_if true  # if_6
-              }
-              $B14: {  # false
-                %34:bool = eq 6u, 11u
-                %35:bool = if %34 [t: $B15, f: $B16] {  # if_7
-                  $B15: {  # true
-                    exit_if true  # if_7
-                  }
-                  $B16: {  # false
-                    %36:bool = eq 6u, 16u
-                    %37:bool = if %36 [t: $B17, f: $B18] {  # if_8
-                      $B17: {  # true
-                        exit_if true  # if_8
-                      }
-                      $B18: {  # false
-                        %38:bool = eq 6u, 21u
-                        %39:bool = if %38 [t: $B19, f: $B20] {  # if_9
-                          $B19: {  # true
-                            exit_if true  # if_9
-                          }
-                          $B20: {  # false
-                            %40:bool = eq 6u, 26u
-                            %41:bool = if %40 [t: $B21, f: $B22] {  # if_10
-                              $B21: {  # true
-                                exit_if true  # if_10
-                              }
-                              $B22: {  # false
-                                exit_if false  # if_10
-                              }
-                            }
-                            exit_if %41  # if_9
-                          }
-                        }
-                        exit_if %39  # if_8
-                      }
-                    }
-                    exit_if %37  # if_7
-                  }
-                }
-                exit_if %35  # if_6
-              }
-            }
-            exit_if %33  # if_5
-          }
-        }
-        exit_if %31  # if_4
+        exit_if true  # if_4
       }
       $B10: {  # false
         exit_if true  # if_4
       }
     }
-    %42:vec4<f32> = if %use_sampler [t: $B23, f: $B24] {  # if_11
-      $B23: {  # true
-        %43:vec4<f32> = textureSample %8, %27, vec2<f32>(0.0f)
-        exit_if %43  # if_11
+    %30:vec4<f32> = if %use_sampler [t: $B11, f: $B12] {  # if_5
+      $B11: {  # true
+        %31:vec4<f32> = textureSample %8, %27, vec2<f32>(0.0f)
+        exit_if %31  # if_5
       }
-      $B24: {  # false
-        %44:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
-        %45:u32 = load %44
-        %46:u32 = add 5u, %45
-        %47:ptr<handle, sampler, read> = access %5, %46
-        %48:sampler = load %47
-        %49:vec4<f32> = textureSample %8, %48, vec2<f32>(0.0f)
-        exit_if %49  # if_11
+      $B12: {  # false
+        %32:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
+        %33:u32 = load %32
+        %34:u32 = add 5u, %33
+        %35:ptr<handle, sampler, read> = access %5, %34
+        %36:sampler = load %35
+        %37:vec4<f32> = textureSample %8, %36, vec2<f32>(0.0f)
+        exit_if %37  # if_5
       }
     }
     ret
@@ -1694,82 +1534,28 @@
     %29:bool = eq %sampler_kind, 40u
     %use_sampler:bool = if %29 [t: $B9, f: $B10] {  # if_4
       $B9: {  # true
-        %31:bool = eq 6u, 1u
-        %32:bool = if %31 [t: $B11, f: $B12] {  # if_5
-          $B11: {  # true
-            exit_if true  # if_5
-          }
-          $B12: {  # false
-            %33:bool = eq 6u, 6u
-            %34:bool = if %33 [t: $B13, f: $B14] {  # if_6
-              $B13: {  # true
-                exit_if true  # if_6
-              }
-              $B14: {  # false
-                %35:bool = eq 6u, 11u
-                %36:bool = if %35 [t: $B15, f: $B16] {  # if_7
-                  $B15: {  # true
-                    exit_if true  # if_7
-                  }
-                  $B16: {  # false
-                    %37:bool = eq 6u, 16u
-                    %38:bool = if %37 [t: $B17, f: $B18] {  # if_8
-                      $B17: {  # true
-                        exit_if true  # if_8
-                      }
-                      $B18: {  # false
-                        %39:bool = eq 6u, 21u
-                        %40:bool = if %39 [t: $B19, f: $B20] {  # if_9
-                          $B19: {  # true
-                            exit_if true  # if_9
-                          }
-                          $B20: {  # false
-                            %41:bool = eq 6u, 26u
-                            %42:bool = if %41 [t: $B21, f: $B22] {  # if_10
-                              $B21: {  # true
-                                exit_if true  # if_10
-                              }
-                              $B22: {  # false
-                                exit_if false  # if_10
-                              }
-                            }
-                            exit_if %42  # if_9
-                          }
-                        }
-                        exit_if %40  # if_8
-                      }
-                    }
-                    exit_if %38  # if_7
-                  }
-                }
-                exit_if %36  # if_6
-              }
-            }
-            exit_if %34  # if_5
-          }
-        }
-        exit_if %32  # if_4
+        exit_if true  # if_4
       }
       $B10: {  # false
         exit_if true  # if_4
       }
     }
-    %43:vec4<f32> = if %use_sampler [t: $B23, f: $B24] {  # if_11
-      $B23: {  # true
-        %44:vec4<f32> = textureSample %5, %28, vec2<f32>(0.0f)
-        exit_if %44  # if_11
+    %31:vec4<f32> = if %use_sampler [t: $B11, f: $B12] {  # if_5
+      $B11: {  # true
+        %32:vec4<f32> = textureSample %5, %28, vec2<f32>(0.0f)
+        exit_if %32  # if_5
       }
-      $B24: {  # false
-        %45:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
-        %46:u32 = load %45
-        %47:u32 = add 0u, %46
-        %48:ptr<storage, u32, read> = access %tint_resource_table_metadata, 1u, %47
-        %49:u32 = load %48
-        %50:u32 = shr %49, 16u
-        %51:ptr<handle, sampler, read> = access %2, %50
-        %52:sampler = load %51
-        %53:vec4<f32> = textureSample %5, %52, vec2<f32>(0.0f)
-        exit_if %53  # if_11
+      $B12: {  # false
+        %33:ptr<storage, u32, read> = access %tint_resource_table_metadata, 0u
+        %34:u32 = load %33
+        %35:u32 = add 0u, %34
+        %36:ptr<storage, u32, read> = access %tint_resource_table_metadata, 1u, %35
+        %37:u32 = load %36
+        %38:u32 = shr %37, 16u
+        %39:ptr<handle, sampler, read> = access %2, %38
+        %40:sampler = load %39
+        %41:vec4<f32> = textureSample %5, %40, vec2<f32>(0.0f)
+        exit_if %41  # if_5
       }
     }
     ret
diff --git a/src/tint/lang/core/type/resource_type.cc b/src/tint/lang/core/type/resource_type.cc
index 9b5e3ea..ae6d13b 100644
--- a/src/tint/lang/core/type/resource_type.cc
+++ b/src/tint/lang/core/type/resource_type.cc
@@ -361,14 +361,4 @@
         [](Default) -> std::vector<ResourceType> { return {}; });
 }
 
-static const std::array kFilterableResources = {
-    ResourceType::kTexture1d_f32_filterable,      ResourceType::kTexture2d_f32_filterable,
-    ResourceType::kTexture2dArray_f32_filterable, ResourceType::kTexture3d_f32_filterable,
-    ResourceType::kTextureCube_f32_filterable,    ResourceType::kTextureCubeArray_f32_filterable,
-};
-
-const std::span<const ResourceType> FilterableResources() {
-    return kFilterableResources;
-}
-
 }  // namespace tint::core::type
diff --git a/src/tint/lang/core/type/resource_type.h b/src/tint/lang/core/type/resource_type.h
index d49e344..5481365 100644
--- a/src/tint/lang/core/type/resource_type.h
+++ b/src/tint/lang/core/type/resource_type.h
@@ -41,9 +41,6 @@
 // type that could be filterable, the type returns the filterable resource type
 ResourceType DefaultResourceTypeFor(const core::type::Type* in_type);
 
-// Returns the filterable types
-const std::span<const ResourceType> FilterableResources();
-
 // Converts a `ResourceType` back into a `core::type::Type`
 const core::type::Type* ResourceTypeToType(core::type::Manager& ty, ResourceType type);
 
diff --git a/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.dxc.hlsl b/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.dxc.hlsl
index fe5016e..87d4550 100644
--- a/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.dxc.hlsl
+++ b/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.dxc.hlsl
@@ -56,58 +56,22 @@
   uint v_13 = v_12;
   bool v_14 = false;
   if ((sampler_kind == 40u)) {
-    bool v_15 = false;
-    if ((texture_kind == 1u)) {
-      v_15 = true;
-    } else {
-      bool v_16 = false;
-      if ((texture_kind == 6u)) {
-        v_16 = true;
-      } else {
-        bool v_17 = false;
-        if ((texture_kind == 11u)) {
-          v_17 = true;
-        } else {
-          bool v_18 = false;
-          if ((texture_kind == 16u)) {
-            v_18 = true;
-          } else {
-            bool v_19 = false;
-            if ((texture_kind == 21u)) {
-              v_19 = true;
-            } else {
-              bool v_20 = false;
-              if ((texture_kind == 26u)) {
-                v_20 = true;
-              } else {
-                v_20 = false;
-              }
-              v_19 = v_20;
-            }
-            v_18 = v_19;
-          }
-          v_17 = v_18;
-        }
-        v_16 = v_17;
-      }
-      v_15 = v_16;
-    }
-    v_14 = v_15;
+    v_14 = (texture_kind == 6u);
   } else {
     v_14 = true;
   }
-  float4 v_21 = (0.0f).xxxx;
+  float4 v_15 = (0.0f).xxxx;
   if (v_14) {
-    v_21 = tint_resource_table_array[v_7].Sample(tint_resource_table_array_2[v_13], (0.0f).xx);
+    v_15 = tint_resource_table_array[v_7].Sample(tint_resource_table_array_2[v_13], (0.0f).xx);
   } else {
-    uint v_22 = (4u + tint_resource_table_metadata.Load(0u));
-    v_21 = tint_resource_table_array[v_7].Sample(tint_resource_table_array_2[v_22], (0.0f).xx);
+    uint v_16 = (4u + tint_resource_table_metadata.Load(0u));
+    v_15 = tint_resource_table_array[v_7].Sample(tint_resource_table_array_2[v_16], (0.0f).xx);
   }
-  return v_21;
+  return v_15;
 }
 
 fs_outputs fs() {
-  fs_outputs v_23 = {fs_inner()};
-  return v_23;
+  fs_outputs v_17 = {fs_inner()};
+  return v_17;
 }
 
diff --git a/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.spvasm b/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.spvasm
index 468b07b..2cedb0c 100644
--- a/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.spvasm
+++ b/test/tint/extensions/resource_table/access_as_constant_sampler.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 1
-; Bound: 163
+; Bound: 130
 ; Schema: 0
                OpCapability Shader
                OpCapability RuntimeDescriptorArray
@@ -77,15 +77,11 @@
      %v2uint = OpTypeVector %uint 2
      %v2bool = OpTypeVector %bool 2
      %uint_4 = OpConstant %uint 4
-        %122 = OpTypeSampledImage %4
+        %116 = OpTypeSampledImage %4
     %v2float = OpTypeVector %float 2
-        %123 = OpConstantNull %v2float
-    %uint_11 = OpConstant %uint 11
-    %uint_16 = OpConstant %uint 16
-    %uint_21 = OpConstant %uint 21
-    %uint_26 = OpConstant %uint 26
+        %117 = OpConstantNull %v2float
        %void = OpTypeVoid
-        %160 = OpTypeFunction %void
+        %127 = OpTypeFunction %void
    %fs_inner = OpFunction %v4float None %22
          %23 = OpLabel
          %24 = OpBitcast %uint %int_0
@@ -96,12 +92,12 @@
                OpSelectionMerge %35 None
                OpBranchConditional %33 %36 %37
          %36 = OpLabel
-         %92 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %24
-         %94 = OpLoad %uint %92 None
-         %96 = OpCompositeConstruct %v3uint %94 %94 %94
-         %97 = OpCompositeConstruct %v3uint %uint_6 %uint_7 %uint_34
-        %100 = OpIEqual %v3bool %96 %97
-         %39 = OpAny %bool %100
+         %91 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %24
+         %93 = OpLoad %uint %91 None
+         %95 = OpCompositeConstruct %v3uint %93 %93 %93
+         %96 = OpCompositeConstruct %v3uint %uint_6 %uint_7 %uint_34
+         %99 = OpIEqual %v3bool %95 %96
+         %39 = OpAny %bool %99
                OpBranch %35
          %37 = OpLabel
                OpBranch %35
@@ -110,8 +106,8 @@
                OpSelectionMerge %41 None
                OpBranchConditional %38 %42 %43
          %42 = OpLabel
-        %102 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %24
-         %45 = OpLoad %uint %102 None
+        %101 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %24
+         %45 = OpLoad %uint %101 None
                OpBranch %41
          %43 = OpLabel
                OpBranch %41
@@ -122,9 +118,9 @@
          %48 = OpLabel
                OpBranch %47
          %49 = OpLabel
-        %103 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-        %104 = OpLoad %uint %103 None
-         %51 = OpIAdd %uint %uint_0 %104
+        %102 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+        %103 = OpLoad %uint %102 None
+         %51 = OpIAdd %uint %uint_0 %103
                OpBranch %47
          %47 = OpLabel
          %50 = OpPhi %uint %24 %48 %51 %49
@@ -136,12 +132,12 @@
                OpSelectionMerge %58 None
                OpBranchConditional %57 %59 %60
          %59 = OpLabel
-        %105 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %27
-        %106 = OpLoad %uint %105 None
-        %108 = OpCompositeConstruct %v2uint %106 %106
-        %109 = OpCompositeConstruct %v2uint %uint_40 %uint_41
-        %110 = OpIEqual %v2bool %108 %109
-         %62 = OpAny %bool %110
+        %104 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %27
+        %105 = OpLoad %uint %104 None
+        %107 = OpCompositeConstruct %v2uint %105 %105
+        %108 = OpCompositeConstruct %v2uint %uint_40 %uint_41
+        %109 = OpIEqual %v2bool %107 %108
+         %62 = OpAny %bool %109
                OpBranch %58
          %60 = OpLabel
                OpBranch %58
@@ -150,8 +146,8 @@
                OpSelectionMerge %63 None
                OpBranchConditional %61 %64 %65
          %64 = OpLabel
-        %112 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %27
-         %67 = OpLoad %uint %112 None
+        %111 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %27
+         %67 = OpLoad %uint %111 None
                OpBranch %63
          %65 = OpLabel
                OpBranch %63
@@ -162,9 +158,9 @@
          %70 = OpLabel
                OpBranch %69
          %71 = OpLabel
-        %113 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-        %114 = OpLoad %uint %113 None
-         %73 = OpIAdd %uint %uint_4 %114
+        %112 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+        %113 = OpLoad %uint %112 None
+         %73 = OpIAdd %uint %uint_4 %113
                OpBranch %69
          %69 = OpLabel
          %72 = OpPhi %uint %27 %70 %73 %71
@@ -174,87 +170,34 @@
                OpSelectionMerge %79 None
                OpBranchConditional %77 %80 %81
          %80 = OpLabel
-        %116 = OpIEqual %bool %texture_kind %uint_1
-               OpSelectionMerge %82 None
-               OpBranchConditional %116 %117 %118
-        %117 = OpLabel
-               OpBranch %82
-        %118 = OpLabel
-        %131 = OpIEqual %bool %texture_kind %uint_6
-               OpSelectionMerge %119 None
-               OpBranchConditional %131 %132 %133
-        %132 = OpLabel
-               OpBranch %119
-        %133 = OpLabel
-        %136 = OpIEqual %bool %texture_kind %uint_11
-               OpSelectionMerge %134 None
-               OpBranchConditional %136 %138 %139
-        %138 = OpLabel
-               OpBranch %134
-        %139 = OpLabel
-        %142 = OpIEqual %bool %texture_kind %uint_16
-               OpSelectionMerge %140 None
-               OpBranchConditional %142 %144 %145
-        %144 = OpLabel
-               OpBranch %140
-        %145 = OpLabel
-        %148 = OpIEqual %bool %texture_kind %uint_21
-               OpSelectionMerge %146 None
-               OpBranchConditional %148 %150 %151
-        %150 = OpLabel
-               OpBranch %146
-        %151 = OpLabel
-        %154 = OpIEqual %bool %texture_kind %uint_26
-               OpSelectionMerge %152 None
-               OpBranchConditional %154 %156 %157
-        %156 = OpLabel
-               OpBranch %152
-        %157 = OpLabel
-               OpBranch %152
-        %152 = OpLabel
-        %153 = OpPhi %bool %true %156 %false %157
-               OpBranch %146
-        %146 = OpLabel
-        %147 = OpPhi %bool %true %150 %153 %152
-               OpBranch %140
-        %140 = OpLabel
-        %141 = OpPhi %bool %true %144 %147 %146
-               OpBranch %134
-        %134 = OpLabel
-        %135 = OpPhi %bool %true %138 %141 %140
-               OpBranch %119
-        %119 = OpLabel
-        %120 = OpPhi %bool %true %132 %135 %134
-               OpBranch %82
-         %82 = OpLabel
-         %85 = OpPhi %bool %true %117 %120 %119
+         %83 = OpIEqual %bool %texture_kind %uint_6
                OpBranch %79
          %81 = OpLabel
                OpBranch %79
          %79 = OpLabel
-%use_sampler = OpPhi %bool %true %81 %85 %82
-               OpSelectionMerge %86 None
-               OpBranchConditional %use_sampler %87 %88
-         %87 = OpLabel
-        %121 = OpSampledImage %122 %54 %76
-         %90 = OpImageSampleImplicitLod %v4float %121 %123 None
-               OpBranch %86
-         %88 = OpLabel
-        %125 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-        %126 = OpLoad %uint %125 None
-        %127 = OpIAdd %uint %uint_4 %126
-        %128 = OpAccessChain %_ptr_UniformConstant_12 %9 %127
-        %129 = OpLoad %12 %128 None
-        %130 = OpSampledImage %122 %54 %129
-         %91 = OpImageSampleImplicitLod %v4float %130 %123 None
-               OpBranch %86
+%use_sampler = OpPhi %bool %83 %80 %true %81
+               OpSelectionMerge %85 None
+               OpBranchConditional %use_sampler %86 %87
          %86 = OpLabel
-         %89 = OpPhi %v4float %90 %87 %91 %88
-               OpReturnValue %89
+        %115 = OpSampledImage %116 %54 %76
+         %89 = OpImageSampleImplicitLod %v4float %115 %117 None
+               OpBranch %85
+         %87 = OpLabel
+        %119 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+        %120 = OpLoad %uint %119 None
+        %121 = OpIAdd %uint %uint_4 %120
+        %122 = OpAccessChain %_ptr_UniformConstant_12 %9 %121
+        %123 = OpLoad %12 %122 None
+        %124 = OpSampledImage %116 %54 %123
+         %90 = OpImageSampleImplicitLod %v4float %124 %117 None
+               OpBranch %85
+         %85 = OpLabel
+         %88 = OpPhi %v4float %89 %86 %90 %87
+               OpReturnValue %88
                OpFunctionEnd
-         %fs = OpFunction %void None %160
-        %161 = OpLabel
-        %162 = OpFunctionCall %v4float %fs_inner
-               OpStore %fs_loc0_Output %162 None
+         %fs = OpFunction %void None %127
+        %128 = OpLabel
+        %129 = OpFunctionCall %v4float %fs_inner
+               OpStore %fs_loc0_Output %129 None
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.dxc.hlsl b/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.dxc.hlsl
index cd26077..4577cbd 100644
--- a/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.dxc.hlsl
+++ b/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.dxc.hlsl
@@ -32,54 +32,18 @@
     v_5 = (0u + tint_resource_table_metadata.Load(0u));
   }
   uint v_6 = v_5;
-  bool v_7 = false;
-  if ((texture_kind == 1u)) {
-    v_7 = true;
+  float4 v_7 = (0.0f).xxxx;
+  if ((texture_kind == 6u)) {
+    v_7 = tint_resource_table_array[v_6].Sample(s, (0.0f).xx);
   } else {
-    bool v_8 = false;
-    if ((texture_kind == 6u)) {
-      v_8 = true;
-    } else {
-      bool v_9 = false;
-      if ((texture_kind == 11u)) {
-        v_9 = true;
-      } else {
-        bool v_10 = false;
-        if ((texture_kind == 16u)) {
-          v_10 = true;
-        } else {
-          bool v_11 = false;
-          if ((texture_kind == 21u)) {
-            v_11 = true;
-          } else {
-            bool v_12 = false;
-            if ((texture_kind == 26u)) {
-              v_12 = true;
-            } else {
-              v_12 = false;
-            }
-            v_11 = v_12;
-          }
-          v_10 = v_11;
-        }
-        v_9 = v_10;
-      }
-      v_8 = v_9;
-    }
-    v_7 = v_8;
+    uint v_8 = (4u + tint_resource_table_metadata.Load(0u));
+    v_7 = tint_resource_table_array[v_6].Sample(tint_resource_table_array_2[v_8], (0.0f).xx);
   }
-  float4 v_13 = (0.0f).xxxx;
-  if (v_7) {
-    v_13 = tint_resource_table_array[v_6].Sample(s, (0.0f).xx);
-  } else {
-    uint v_14 = (4u + tint_resource_table_metadata.Load(0u));
-    v_13 = tint_resource_table_array[v_6].Sample(tint_resource_table_array_2[v_14], (0.0f).xx);
-  }
-  return v_13;
+  return v_7;
 }
 
 fs_outputs fs() {
-  fs_outputs v_15 = {fs_inner()};
-  return v_15;
+  fs_outputs v_9 = {fs_inner()};
+  return v_9;
 }
 
diff --git a/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.spvasm b/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.spvasm
index ec2e8d3..bed4116 100644
--- a/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.spvasm
+++ b/test/tint/extensions/resource_table/access_bindful_sampler_filtering.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 1
-; Bound: 126
+; Bound: 92
 ; Schema: 0
                OpCapability Shader
                OpCapability RuntimeDescriptorArray
@@ -67,21 +67,16 @@
      %uint_6 = OpConstant %uint 6
 %_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
      %uint_1 = OpConstant %uint 1
-       %true = OpConstantTrue %bool
      %v3uint = OpTypeVector %uint 3
      %uint_7 = OpConstant %uint 7
     %uint_34 = OpConstant %uint 34
      %v3bool = OpTypeVector %bool 3
-         %89 = OpTypeSampledImage %7
+         %77 = OpTypeSampledImage %7
     %v2float = OpTypeVector %float 2
-         %90 = OpConstantNull %v2float
+         %78 = OpConstantNull %v2float
      %uint_4 = OpConstant %uint 4
-    %uint_11 = OpConstant %uint 11
-    %uint_16 = OpConstant %uint 16
-    %uint_21 = OpConstant %uint 21
-    %uint_26 = OpConstant %uint 26
        %void = OpTypeVoid
-        %123 = OpTypeFunction %void
+         %89 = OpTypeFunction %void
    %fs_inner = OpFunction %v4float None %24
          %25 = OpLabel
          %26 = OpBitcast %uint %int_0
@@ -92,12 +87,12 @@
                OpSelectionMerge %36 None
                OpBranchConditional %34 %37 %38
          %37 = OpLabel
-         %71 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
-         %72 = OpLoad %uint %71 None
-         %74 = OpCompositeConstruct %v3uint %72 %72 %72
-         %75 = OpCompositeConstruct %v3uint %uint_6 %uint_7 %uint_34
-         %78 = OpIEqual %v3bool %74 %75
-         %40 = OpAny %bool %78
+         %63 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
+         %65 = OpLoad %uint %63 None
+         %67 = OpCompositeConstruct %v3uint %65 %65 %65
+         %68 = OpCompositeConstruct %v3uint %uint_6 %uint_7 %uint_34
+         %71 = OpIEqual %v3bool %67 %68
+         %40 = OpAny %bool %71
                OpBranch %36
          %38 = OpLabel
                OpBranch %36
@@ -106,8 +101,8 @@
                OpSelectionMerge %42 None
                OpBranchConditional %39 %43 %44
          %43 = OpLabel
-         %80 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
-         %46 = OpLoad %uint %80 None
+         %73 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
+         %46 = OpLoad %uint %73 None
                OpBranch %42
          %44 = OpLabel
                OpBranch %42
@@ -118,90 +113,37 @@
          %49 = OpLabel
                OpBranch %48
          %50 = OpLabel
-         %81 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-         %82 = OpLoad %uint %81 None
-         %52 = OpIAdd %uint %uint_0 %82
+         %74 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+         %75 = OpLoad %uint %74 None
+         %52 = OpIAdd %uint %uint_0 %75
                OpBranch %48
          %48 = OpLabel
          %51 = OpPhi %uint %26 %49 %52 %50
          %53 = OpAccessChain %_ptr_UniformConstant_7 %4 %51
          %55 = OpLoad %7 %53 None
-         %56 = OpIEqual %bool %texture_kind %uint_1
-               OpSelectionMerge %58 None
-               OpBranchConditional %56 %59 %60
-         %59 = OpLabel
-               OpBranch %58
-         %60 = OpLabel
-         %83 = OpIEqual %bool %texture_kind %uint_6
-               OpSelectionMerge %61 None
-               OpBranchConditional %83 %84 %85
-         %84 = OpLabel
-               OpBranch %61
-         %85 = OpLabel
-         %99 = OpIEqual %bool %texture_kind %uint_11
-               OpSelectionMerge %86 None
-               OpBranchConditional %99 %101 %102
-        %101 = OpLabel
-               OpBranch %86
-        %102 = OpLabel
-        %105 = OpIEqual %bool %texture_kind %uint_16
-               OpSelectionMerge %103 None
-               OpBranchConditional %105 %107 %108
-        %107 = OpLabel
-               OpBranch %103
-        %108 = OpLabel
-        %111 = OpIEqual %bool %texture_kind %uint_21
-               OpSelectionMerge %109 None
-               OpBranchConditional %111 %113 %114
-        %113 = OpLabel
-               OpBranch %109
-        %114 = OpLabel
-        %117 = OpIEqual %bool %texture_kind %uint_26
-               OpSelectionMerge %115 None
-               OpBranchConditional %117 %119 %120
-        %119 = OpLabel
-               OpBranch %115
-        %120 = OpLabel
-               OpBranch %115
-        %115 = OpLabel
-        %116 = OpPhi %bool %true %119 %false %120
-               OpBranch %109
-        %109 = OpLabel
-        %110 = OpPhi %bool %true %113 %116 %115
-               OpBranch %103
-        %103 = OpLabel
-        %104 = OpPhi %bool %true %107 %110 %109
-               OpBranch %86
-         %86 = OpLabel
-         %87 = OpPhi %bool %true %101 %104 %103
-               OpBranch %61
-         %61 = OpLabel
-         %64 = OpPhi %bool %true %84 %87 %86
-               OpBranch %58
+         %56 = OpIEqual %bool %texture_kind %uint_6
+               OpSelectionMerge %57 None
+               OpBranchConditional %56 %58 %59
          %58 = OpLabel
-         %62 = OpPhi %bool %true %59 %64 %61
-               OpSelectionMerge %65 None
-               OpBranchConditional %62 %66 %67
-         %66 = OpLabel
-         %88 = OpSampledImage %89 %55 %29
-         %69 = OpImageSampleImplicitLod %v4float %88 %90 None
-               OpBranch %65
-         %67 = OpLabel
-         %92 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-         %93 = OpLoad %uint %92 None
-         %94 = OpIAdd %uint %uint_4 %93
-         %96 = OpAccessChain %_ptr_UniformConstant_3 %12 %94
-         %97 = OpLoad %3 %96 None
-         %98 = OpSampledImage %89 %55 %97
-         %70 = OpImageSampleImplicitLod %v4float %98 %90 None
-               OpBranch %65
-         %65 = OpLabel
-         %68 = OpPhi %v4float %69 %66 %70 %67
-               OpReturnValue %68
+         %76 = OpSampledImage %77 %55 %29
+         %61 = OpImageSampleImplicitLod %v4float %76 %78 None
+               OpBranch %57
+         %59 = OpLabel
+         %80 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+         %81 = OpLoad %uint %80 None
+         %82 = OpIAdd %uint %uint_4 %81
+         %84 = OpAccessChain %_ptr_UniformConstant_3 %12 %82
+         %85 = OpLoad %3 %84 None
+         %86 = OpSampledImage %77 %55 %85
+         %62 = OpImageSampleImplicitLod %v4float %86 %78 None
+               OpBranch %57
+         %57 = OpLabel
+         %60 = OpPhi %v4float %61 %58 %62 %59
+               OpReturnValue %60
                OpFunctionEnd
-         %fs = OpFunction %void None %123
-        %124 = OpLabel
-        %125 = OpFunctionCall %v4float %fs_inner
-               OpStore %fs_loc0_Output %125 None
+         %fs = OpFunction %void None %89
+         %90 = OpLabel
+         %91 = OpFunctionCall %v4float %fs_inner
+               OpStore %fs_loc0_Output %91 None
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.dxc.hlsl b/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.dxc.hlsl
index 093c48f..669f934 100644
--- a/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.dxc.hlsl
+++ b/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.dxc.hlsl
@@ -34,58 +34,22 @@
   uint v_6 = v_5;
   bool v_7 = false;
   if ((sampler_kind == 40u)) {
-    bool v_8 = false;
-    if ((6u == 1u)) {
-      v_8 = true;
-    } else {
-      bool v_9 = false;
-      if ((6u == 6u)) {
-        v_9 = true;
-      } else {
-        bool v_10 = false;
-        if ((6u == 11u)) {
-          v_10 = true;
-        } else {
-          bool v_11 = false;
-          if ((6u == 16u)) {
-            v_11 = true;
-          } else {
-            bool v_12 = false;
-            if ((6u == 21u)) {
-              v_12 = true;
-            } else {
-              bool v_13 = false;
-              if ((6u == 26u)) {
-                v_13 = true;
-              } else {
-                v_13 = false;
-              }
-              v_12 = v_13;
-            }
-            v_11 = v_12;
-          }
-          v_10 = v_11;
-        }
-        v_9 = v_10;
-      }
-      v_8 = v_9;
-    }
-    v_7 = v_8;
+    v_7 = true;
   } else {
     v_7 = true;
   }
-  float4 v_14 = (0.0f).xxxx;
+  float4 v_8 = (0.0f).xxxx;
   if (v_7) {
-    v_14 = t.Sample(tint_resource_table_array_2[v_6], (0.0f).xx);
+    v_8 = t.Sample(tint_resource_table_array_2[v_6], (0.0f).xx);
   } else {
-    uint v_15 = (4u + tint_resource_table_metadata.Load(0u));
-    v_14 = t.Sample(tint_resource_table_array_2[v_15], (0.0f).xx);
+    uint v_9 = (4u + tint_resource_table_metadata.Load(0u));
+    v_8 = t.Sample(tint_resource_table_array_2[v_9], (0.0f).xx);
   }
-  return v_14;
+  return v_8;
 }
 
 fs_outputs fs() {
-  fs_outputs v_16 = {fs_inner()};
-  return v_16;
+  fs_outputs v_10 = {fs_inner()};
+  return v_10;
 }
 
diff --git a/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.spvasm b/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.spvasm
index dee3b04..7cd16d7 100644
--- a/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.spvasm
+++ b/test/tint/extensions/resource_table/access_bindful_texture.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 1
-; Bound: 131
+; Bound: 96
 ; Schema: 0
                OpCapability Shader
                OpCapability RuntimeDescriptorArray
@@ -73,16 +73,11 @@
      %v2uint = OpTypeVector %uint 2
      %v2bool = OpTypeVector %bool 2
      %uint_4 = OpConstant %uint 4
-     %uint_6 = OpConstant %uint 6
-         %90 = OpTypeSampledImage %3
+         %82 = OpTypeSampledImage %3
     %v2float = OpTypeVector %float 2
-         %91 = OpConstantNull %v2float
-    %uint_11 = OpConstant %uint 11
-    %uint_16 = OpConstant %uint 16
-    %uint_21 = OpConstant %uint 21
-    %uint_26 = OpConstant %uint 26
+         %83 = OpConstantNull %v2float
        %void = OpTypeVoid
-        %128 = OpTypeFunction %void
+         %93 = OpTypeFunction %void
    %fs_inner = OpFunction %v4float None %24
          %25 = OpLabel
          %26 = OpBitcast %uint %int_0
@@ -93,12 +88,12 @@
                OpSelectionMerge %36 None
                OpBranchConditional %34 %37 %38
          %37 = OpLabel
-         %71 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
-         %73 = OpLoad %uint %71 None
-         %75 = OpCompositeConstruct %v2uint %73 %73
-         %76 = OpCompositeConstruct %v2uint %uint_40 %uint_41
-         %77 = OpIEqual %v2bool %75 %76
-         %40 = OpAny %bool %77
+         %69 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
+         %71 = OpLoad %uint %69 None
+         %73 = OpCompositeConstruct %v2uint %71 %71
+         %74 = OpCompositeConstruct %v2uint %uint_40 %uint_41
+         %75 = OpIEqual %v2bool %73 %74
+         %40 = OpAny %bool %75
                OpBranch %36
          %38 = OpLabel
                OpBranch %36
@@ -107,8 +102,8 @@
                OpSelectionMerge %42 None
                OpBranchConditional %39 %43 %44
          %43 = OpLabel
-         %79 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
-         %46 = OpLoad %uint %79 None
+         %77 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %26
+         %46 = OpLoad %uint %77 None
                OpBranch %42
          %44 = OpLabel
                OpBranch %42
@@ -119,9 +114,9 @@
          %49 = OpLabel
                OpBranch %48
          %50 = OpLabel
-         %80 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-         %81 = OpLoad %uint %80 None
-         %52 = OpIAdd %uint %uint_4 %81
+         %78 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+         %79 = OpLoad %uint %78 None
+         %52 = OpIAdd %uint %uint_4 %79
                OpBranch %48
          %48 = OpLabel
          %51 = OpPhi %uint %26 %49 %52 %50
@@ -131,87 +126,33 @@
                OpSelectionMerge %58 None
                OpBranchConditional %56 %59 %60
          %59 = OpLabel
-         %83 = OpIEqual %bool %uint_6 %uint_1
-               OpSelectionMerge %61 None
-               OpBranchConditional %83 %85 %86
-         %85 = OpLabel
-               OpBranch %61
-         %86 = OpLabel
-         %99 = OpIEqual %bool %uint_6 %uint_6
-               OpSelectionMerge %87 None
-               OpBranchConditional %99 %100 %101
-        %100 = OpLabel
-               OpBranch %87
-        %101 = OpLabel
-        %104 = OpIEqual %bool %uint_6 %uint_11
-               OpSelectionMerge %102 None
-               OpBranchConditional %104 %106 %107
-        %106 = OpLabel
-               OpBranch %102
-        %107 = OpLabel
-        %110 = OpIEqual %bool %uint_6 %uint_16
-               OpSelectionMerge %108 None
-               OpBranchConditional %110 %112 %113
-        %112 = OpLabel
-               OpBranch %108
-        %113 = OpLabel
-        %116 = OpIEqual %bool %uint_6 %uint_21
-               OpSelectionMerge %114 None
-               OpBranchConditional %116 %118 %119
-        %118 = OpLabel
-               OpBranch %114
-        %119 = OpLabel
-        %122 = OpIEqual %bool %uint_6 %uint_26
-               OpSelectionMerge %120 None
-               OpBranchConditional %122 %124 %125
-        %124 = OpLabel
-               OpBranch %120
-        %125 = OpLabel
-               OpBranch %120
-        %120 = OpLabel
-        %121 = OpPhi %bool %true %124 %false %125
-               OpBranch %114
-        %114 = OpLabel
-        %115 = OpPhi %bool %true %118 %121 %120
-               OpBranch %108
-        %108 = OpLabel
-        %109 = OpPhi %bool %true %112 %115 %114
-               OpBranch %102
-        %102 = OpLabel
-        %103 = OpPhi %bool %true %106 %109 %108
-               OpBranch %87
-         %87 = OpLabel
-         %88 = OpPhi %bool %true %100 %103 %102
-               OpBranch %61
-         %61 = OpLabel
-         %64 = OpPhi %bool %true %85 %88 %87
                OpBranch %58
          %60 = OpLabel
                OpBranch %58
          %58 = OpLabel
-%use_sampler = OpPhi %bool %true %60 %64 %61
-               OpSelectionMerge %65 None
-               OpBranchConditional %use_sampler %66 %67
-         %66 = OpLabel
-         %89 = OpSampledImage %90 %29 %55
-         %69 = OpImageSampleImplicitLod %v4float %89 %91 None
-               OpBranch %65
-         %67 = OpLabel
-         %93 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-         %94 = OpLoad %uint %93 None
-         %95 = OpIAdd %uint %uint_4 %94
-         %96 = OpAccessChain %_ptr_UniformConstant_14 %11 %95
-         %97 = OpLoad %14 %96 None
-         %98 = OpSampledImage %90 %29 %97
-         %70 = OpImageSampleImplicitLod %v4float %98 %91 None
-               OpBranch %65
+%use_sampler = OpPhi %bool %true %59 %true %60
+               OpSelectionMerge %63 None
+               OpBranchConditional %use_sampler %64 %65
+         %64 = OpLabel
+         %81 = OpSampledImage %82 %29 %55
+         %67 = OpImageSampleImplicitLod %v4float %81 %83 None
+               OpBranch %63
          %65 = OpLabel
-         %68 = OpPhi %v4float %69 %66 %70 %67
-               OpReturnValue %68
+         %85 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+         %86 = OpLoad %uint %85 None
+         %87 = OpIAdd %uint %uint_4 %86
+         %88 = OpAccessChain %_ptr_UniformConstant_14 %11 %87
+         %89 = OpLoad %14 %88 None
+         %90 = OpSampledImage %82 %29 %89
+         %68 = OpImageSampleImplicitLod %v4float %90 %83 None
+               OpBranch %63
+         %63 = OpLabel
+         %66 = OpPhi %v4float %67 %64 %68 %65
+               OpReturnValue %66
                OpFunctionEnd
-         %fs = OpFunction %void None %128
-        %129 = OpLabel
-        %130 = OpFunctionCall %v4float %fs_inner
-               OpStore %fs_loc0_Output %130 None
+         %fs = OpFunction %void None %93
+         %94 = OpLabel
+         %95 = OpFunctionCall %v4float %fs_inner
+               OpStore %fs_loc0_Output %95 None
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/extensions/resource_table/to_let.wgsl.expected.dxc.hlsl b/test/tint/extensions/resource_table/to_let.wgsl.expected.dxc.hlsl
index 5d3737d..d68285f 100644
--- a/test/tint/extensions/resource_table/to_let.wgsl.expected.dxc.hlsl
+++ b/test/tint/extensions/resource_table/to_let.wgsl.expected.dxc.hlsl
@@ -54,58 +54,22 @@
   uint v_11 = v_10;
   bool v_12 = false;
   if ((sampler_kind == 40u)) {
-    bool v_13 = false;
-    if ((texture_kind == 1u)) {
-      v_13 = true;
-    } else {
-      bool v_14 = false;
-      if ((texture_kind == 6u)) {
-        v_14 = true;
-      } else {
-        bool v_15 = false;
-        if ((texture_kind == 11u)) {
-          v_15 = true;
-        } else {
-          bool v_16 = false;
-          if ((texture_kind == 16u)) {
-            v_16 = true;
-          } else {
-            bool v_17 = false;
-            if ((texture_kind == 21u)) {
-              v_17 = true;
-            } else {
-              bool v_18 = false;
-              if ((texture_kind == 26u)) {
-                v_18 = true;
-              } else {
-                v_18 = false;
-              }
-              v_17 = v_18;
-            }
-            v_16 = v_17;
-          }
-          v_15 = v_16;
-        }
-        v_14 = v_15;
-      }
-      v_13 = v_14;
-    }
-    v_12 = v_13;
+    v_12 = (texture_kind == 6u);
   } else {
     v_12 = true;
   }
-  float4 v_19 = (0.0f).xxxx;
+  float4 v_13 = (0.0f).xxxx;
   if (v_12) {
-    v_19 = tint_resource_table_array[v_5].Sample(tint_resource_table_array_2[v_11], (0.0f).xx);
+    v_13 = tint_resource_table_array[v_5].Sample(tint_resource_table_array_2[v_11], (0.0f).xx);
   } else {
-    uint v_20 = (4u + tint_resource_table_metadata.Load(0u));
-    v_19 = tint_resource_table_array[v_5].Sample(tint_resource_table_array_2[v_20], (0.0f).xx);
+    uint v_14 = (4u + tint_resource_table_metadata.Load(0u));
+    v_13 = tint_resource_table_array[v_5].Sample(tint_resource_table_array_2[v_14], (0.0f).xx);
   }
-  return v_19;
+  return v_13;
 }
 
 fs_outputs fs() {
-  fs_outputs v_21 = {fs_inner()};
-  return v_21;
+  fs_outputs v_15 = {fs_inner()};
+  return v_15;
 }
 
diff --git a/test/tint/extensions/resource_table/to_let.wgsl.expected.spvasm b/test/tint/extensions/resource_table/to_let.wgsl.expected.spvasm
index 1c0601c..27baf04 100644
--- a/test/tint/extensions/resource_table/to_let.wgsl.expected.spvasm
+++ b/test/tint/extensions/resource_table/to_let.wgsl.expected.spvasm
@@ -1,7 +1,7 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 1
-; Bound: 160
+; Bound: 127
 ; Schema: 0
                OpCapability Shader
                OpCapability RuntimeDescriptorArray
@@ -76,15 +76,11 @@
      %v2uint = OpTypeVector %uint 2
      %v2bool = OpTypeVector %bool 2
      %uint_4 = OpConstant %uint 4
-        %119 = OpTypeSampledImage %4
+        %113 = OpTypeSampledImage %4
     %v2float = OpTypeVector %float 2
-        %120 = OpConstantNull %v2float
-    %uint_11 = OpConstant %uint 11
-    %uint_16 = OpConstant %uint 16
-    %uint_21 = OpConstant %uint 21
-    %uint_26 = OpConstant %uint 26
+        %114 = OpConstantNull %v2float
        %void = OpTypeVoid
-        %157 = OpTypeFunction %void
+        %124 = OpTypeFunction %void
    %fs_inner = OpFunction %v4float None %22
          %23 = OpLabel
 %tint_storage_metadata_length = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
@@ -93,12 +89,12 @@
                OpSelectionMerge %31 None
                OpBranchConditional %28 %32 %33
          %32 = OpLabel
-         %89 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_2
-         %91 = OpLoad %uint %89 None
-         %93 = OpCompositeConstruct %v3uint %91 %91 %91
-         %94 = OpCompositeConstruct %v3uint %uint_6 %uint_7 %uint_34
-         %97 = OpIEqual %v3bool %93 %94
-         %35 = OpAny %bool %97
+         %88 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_2
+         %90 = OpLoad %uint %88 None
+         %92 = OpCompositeConstruct %v3uint %90 %90 %90
+         %93 = OpCompositeConstruct %v3uint %uint_6 %uint_7 %uint_34
+         %96 = OpIEqual %v3bool %92 %93
+         %35 = OpAny %bool %96
                OpBranch %31
          %33 = OpLabel
                OpBranch %31
@@ -107,8 +103,8 @@
                OpSelectionMerge %37 None
                OpBranchConditional %34 %38 %39
          %38 = OpLabel
-         %99 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_2
-         %41 = OpLoad %uint %99 None
+         %98 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_2
+         %41 = OpLoad %uint %98 None
                OpBranch %37
          %39 = OpLabel
                OpBranch %37
@@ -119,9 +115,9 @@
          %44 = OpLabel
                OpBranch %43
          %45 = OpLabel
-        %100 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-        %101 = OpLoad %uint %100 None
-         %47 = OpIAdd %uint %uint_0 %101
+         %99 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+        %100 = OpLoad %uint %99 None
+         %47 = OpIAdd %uint %uint_0 %100
                OpBranch %43
          %43 = OpLabel
          %46 = OpPhi %uint %uint_2 %44 %47 %45
@@ -133,12 +129,12 @@
                OpSelectionMerge %55 None
                OpBranchConditional %53 %56 %57
          %56 = OpLabel
-        %102 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_3
-        %103 = OpLoad %uint %102 None
-        %105 = OpCompositeConstruct %v2uint %103 %103
-        %106 = OpCompositeConstruct %v2uint %uint_40 %uint_41
-        %107 = OpIEqual %v2bool %105 %106
-         %59 = OpAny %bool %107
+        %101 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_3
+        %102 = OpLoad %uint %101 None
+        %104 = OpCompositeConstruct %v2uint %102 %102
+        %105 = OpCompositeConstruct %v2uint %uint_40 %uint_41
+        %106 = OpIEqual %v2bool %104 %105
+         %59 = OpAny %bool %106
                OpBranch %55
          %57 = OpLabel
                OpBranch %55
@@ -147,8 +143,8 @@
                OpSelectionMerge %60 None
                OpBranchConditional %58 %61 %62
          %61 = OpLabel
-        %109 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_3
-         %64 = OpLoad %uint %109 None
+        %108 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_1 %uint_3
+         %64 = OpLoad %uint %108 None
                OpBranch %60
          %62 = OpLabel
                OpBranch %60
@@ -159,9 +155,9 @@
          %67 = OpLabel
                OpBranch %66
          %68 = OpLabel
-        %110 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-        %111 = OpLoad %uint %110 None
-         %70 = OpIAdd %uint %uint_4 %111
+        %109 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+        %110 = OpLoad %uint %109 None
+         %70 = OpIAdd %uint %uint_4 %110
                OpBranch %66
          %66 = OpLabel
          %69 = OpPhi %uint %uint_3 %67 %70 %68
@@ -171,87 +167,34 @@
                OpSelectionMerge %76 None
                OpBranchConditional %74 %77 %78
          %77 = OpLabel
-        %113 = OpIEqual %bool %texture_kind %uint_1
-               OpSelectionMerge %79 None
-               OpBranchConditional %113 %114 %115
-        %114 = OpLabel
-               OpBranch %79
-        %115 = OpLabel
-        %128 = OpIEqual %bool %texture_kind %uint_6
-               OpSelectionMerge %116 None
-               OpBranchConditional %128 %129 %130
-        %129 = OpLabel
-               OpBranch %116
-        %130 = OpLabel
-        %133 = OpIEqual %bool %texture_kind %uint_11
-               OpSelectionMerge %131 None
-               OpBranchConditional %133 %135 %136
-        %135 = OpLabel
-               OpBranch %131
-        %136 = OpLabel
-        %139 = OpIEqual %bool %texture_kind %uint_16
-               OpSelectionMerge %137 None
-               OpBranchConditional %139 %141 %142
-        %141 = OpLabel
-               OpBranch %137
-        %142 = OpLabel
-        %145 = OpIEqual %bool %texture_kind %uint_21
-               OpSelectionMerge %143 None
-               OpBranchConditional %145 %147 %148
-        %147 = OpLabel
-               OpBranch %143
-        %148 = OpLabel
-        %151 = OpIEqual %bool %texture_kind %uint_26
-               OpSelectionMerge %149 None
-               OpBranchConditional %151 %153 %154
-        %153 = OpLabel
-               OpBranch %149
-        %154 = OpLabel
-               OpBranch %149
-        %149 = OpLabel
-        %150 = OpPhi %bool %true %153 %false %154
-               OpBranch %143
-        %143 = OpLabel
-        %144 = OpPhi %bool %true %147 %150 %149
-               OpBranch %137
-        %137 = OpLabel
-        %138 = OpPhi %bool %true %141 %144 %143
-               OpBranch %131
-        %131 = OpLabel
-        %132 = OpPhi %bool %true %135 %138 %137
-               OpBranch %116
-        %116 = OpLabel
-        %117 = OpPhi %bool %true %129 %132 %131
-               OpBranch %79
-         %79 = OpLabel
-         %82 = OpPhi %bool %true %114 %117 %116
+         %80 = OpIEqual %bool %texture_kind %uint_6
                OpBranch %76
          %78 = OpLabel
                OpBranch %76
          %76 = OpLabel
-%use_sampler = OpPhi %bool %true %78 %82 %79
-               OpSelectionMerge %83 None
-               OpBranchConditional %use_sampler %84 %85
-         %84 = OpLabel
-        %118 = OpSampledImage %119 %50 %73
-         %87 = OpImageSampleImplicitLod %v4float %118 %120 None
-               OpBranch %83
-         %85 = OpLabel
-        %122 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
-        %123 = OpLoad %uint %122 None
-        %124 = OpIAdd %uint %uint_4 %123
-        %125 = OpAccessChain %_ptr_UniformConstant_12 %9 %124
-        %126 = OpLoad %12 %125 None
-        %127 = OpSampledImage %119 %50 %126
-         %88 = OpImageSampleImplicitLod %v4float %127 %120 None
-               OpBranch %83
+%use_sampler = OpPhi %bool %80 %77 %true %78
+               OpSelectionMerge %82 None
+               OpBranchConditional %use_sampler %83 %84
          %83 = OpLabel
-         %86 = OpPhi %v4float %87 %84 %88 %85
-               OpReturnValue %86
+        %112 = OpSampledImage %113 %50 %73
+         %86 = OpImageSampleImplicitLod %v4float %112 %114 None
+               OpBranch %82
+         %84 = OpLabel
+        %116 = OpAccessChain %_ptr_StorageBuffer_uint %tint_resource_table_metadata %uint_0
+        %117 = OpLoad %uint %116 None
+        %118 = OpIAdd %uint %uint_4 %117
+        %119 = OpAccessChain %_ptr_UniformConstant_12 %9 %118
+        %120 = OpLoad %12 %119 None
+        %121 = OpSampledImage %113 %50 %120
+         %87 = OpImageSampleImplicitLod %v4float %121 %114 None
+               OpBranch %82
+         %82 = OpLabel
+         %85 = OpPhi %v4float %86 %83 %87 %84
+               OpReturnValue %85
                OpFunctionEnd
-         %fs = OpFunction %void None %157
-        %158 = OpLabel
-        %159 = OpFunctionCall %v4float %fs_inner
-               OpStore %fs_loc0_Output %159 None
+         %fs = OpFunction %void None %124
+        %125 = OpLabel
+        %126 = OpFunctionCall %v4float %fs_inner
+               OpStore %fs_loc0_Output %126 None
                OpReturn
                OpFunctionEnd