From f66851e37682ce538172b0945908227ada8d21ac Mon Sep 17 00:00:00 2001
From: ReinUsesLisp <reinuseslisp@airmail.cc>
Date: Wed, 21 Apr 2021 02:43:44 -0300
Subject: shader: Use memset to reset instruction arguments

---
 src/shader_recompiler/frontend/ir/microinstruction.cpp | 4 +++-
 src/shader_recompiler/frontend/ir/value.h              | 7 ++++---
 2 files changed, 7 insertions(+), 4 deletions(-)

(limited to 'src/shader_recompiler/frontend/ir')

diff --git a/src/shader_recompiler/frontend/ir/microinstruction.cpp b/src/shader_recompiler/frontend/ir/microinstruction.cpp
index 701746a0cc..e3350931b8 100644
--- a/src/shader_recompiler/frontend/ir/microinstruction.cpp
+++ b/src/shader_recompiler/frontend/ir/microinstruction.cpp
@@ -279,8 +279,10 @@ void Inst::ClearArgs() {
             if (!value.IsImmediate()) {
                 UndoUse(value);
             }
-            value = {};
         }
+        // Reset arguments to null
+        // std::memset was measured to be faster on MSVC than std::ranges:fill
+        std::memset(&args, 0, sizeof(args));
     }
 }
 
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h
index 5425e42a1e..7b20824edc 100644
--- a/src/shader_recompiler/frontend/ir/value.h
+++ b/src/shader_recompiler/frontend/ir/value.h
@@ -34,7 +34,7 @@ struct AssociatedInsts;
 
 class Value {
 public:
-    Value() noexcept : type{IR::Type::Void}, inst{nullptr} {}
+    Value() noexcept = default;
     explicit Value(IR::Inst* value) noexcept;
     explicit Value(IR::Block* value) noexcept;
     explicit Value(IR::Reg value) noexcept;
@@ -78,9 +78,9 @@ public:
 private:
     void ValidateAccess(IR::Type expected) const;
 
-    IR::Type type;
+    IR::Type type{};
     union {
-        IR::Inst* inst;
+        IR::Inst* inst{};
         IR::Block* label;
         IR::Reg reg;
         IR::Pred pred;
@@ -95,6 +95,7 @@ private:
         f64 imm_f64;
     };
 };
+static_assert(static_cast<u32>(IR::Type::Void) == 0, "memset relies on IR::Type being zero");
 static_assert(std::is_trivially_copyable_v<Value>);
 
 template <IR::Type type_>
-- 
cgit v1.2.3-70-g09d2