[tint][ir][ToProgram] Implement bitcast

Change-Id: Ic31d8c26fd1e0c9866c65625baf15e973202477b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/139921
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/ir/to_program.cc b/src/tint/ir/to_program.cc
index 3e30cfb..8fb09b7 100644
--- a/src/tint/ir/to_program.cc
+++ b/src/tint/ir/to_program.cc
@@ -21,6 +21,7 @@
 #include "src/tint/constant/splat.h"
 #include "src/tint/ir/access.h"
 #include "src/tint/ir/binary.h"
+#include "src/tint/ir/bitcast.h"
 #include "src/tint/ir/block.h"
 #include "src/tint/ir/break_if.h"
 #include "src/tint/ir/builtin_call.h"
@@ -507,6 +508,10 @@
                 auto ty = Type(c->Result()->Type());
                 Bind(c->Result(), b.Call(ty, std::move(args)), PtrKind::kPtr);
             },
+            [&](ir::Bitcast* c) {
+                auto ty = Type(c->Result()->Type());
+                Bind(c->Result(), b.Bitcast(ty, args[0]), PtrKind::kPtr);
+            },
             [&](Default) { UNHANDLED_CASE(call); });
     }
 
diff --git a/src/tint/ir/to_program_roundtrip_test.cc b/src/tint/ir/to_program_roundtrip_test.cc
index 14bc8a1..47d8c16 100644
--- a/src/tint/ir/to_program_roundtrip_test.cc
+++ b/src/tint/ir/to_program_roundtrip_test.cc
@@ -347,6 +347,33 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+// Bitcast
+////////////////////////////////////////////////////////////////////////////////
+TEST_F(IRToProgramRoundtripTest, Bitcast_i32_to_u32) {
+    Test(R"(
+fn f(i : i32) {
+  var v : u32 = bitcast<u32>(i);
+}
+)");
+}
+
+TEST_F(IRToProgramRoundtripTest, Bitcast_u32_to_f32) {
+    Test(R"(
+fn f(i : u32) {
+  var v : f32 = bitcast<f32>(i);
+}
+)");
+}
+
+TEST_F(IRToProgramRoundtripTest, Bitcast_f32_to_i32) {
+    Test(R"(
+fn f(i : f32) {
+  var v : i32 = bitcast<i32>(i);
+}
+)");
+}
+
+////////////////////////////////////////////////////////////////////////////////
 // Access
 ////////////////////////////////////////////////////////////////////////////////
 TEST_F(IRToProgramRoundtripTest, Access_Value_vec3f_1) {