Просмотр исходного кода

Prototype for coalescing equivalent specifics of the same generic. (#5314)

This is a working version for coalescing equivalent specifics of the
same generic, with *many* things to add and improve.
Alina Sbirlea 11 месяцев назад
Родитель
Сommit
77afd0678b

+ 263 - 3
toolchain/lower/file_context.cpp

@@ -15,6 +15,8 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Sequence.h"
 #include "llvm/Linker/Linker.h"
+#include "llvm/Support/BLAKE3.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "toolchain/base/kind_switch.h"
 #include "toolchain/lower/constant.h"
@@ -92,6 +94,14 @@ auto FileContext::Run() -> std::unique_ptr<llvm::Module> {
 
   // Specific functions are lowered when we emit a reference to them.
   specific_functions_.resize(sem_ir_->specifics().size());
+  // Additional data stored for specifics, for when attempting to coalesce.
+  // Indexed by `GenericId`.
+  lowered_specifics_.resize(sem_ir_->generics().size());
+  // Indexed by `SpecificId`.
+  lowered_specifics_type_fingerprint_.resize(sem_ir_->specifics().size());
+  lowered_specific_fingerprint_.resize(sem_ir_->specifics().size());
+  equivalent_specifics_.resize(sem_ir_->specifics().size(),
+                               SemIR::SpecificId::None);
 
   // Lower constants.
   constants_.resize(sem_ir_->insts().size());
@@ -138,6 +148,10 @@ auto FileContext::Run() -> std::unique_ptr<llvm::Module> {
     BuildFunctionDefinition(function_id, specific_id);
   }
 
+  // Find equivalent specifics (from the same generic), replace all uses and
+  // remove duplicately lowered function definitions.
+  CoalesceEquivalentSpecifics();
+
   // Append `__global_init` to `llvm::global_ctors` to initialize global
   // variables.
   if (sem_ir().global_ctor_id().has_value()) {
@@ -158,6 +172,229 @@ auto FileContext::Run() -> std::unique_ptr<llvm::Module> {
   return std::move(llvm_module_);
 }
 
+auto FileContext::InsertPair(
+    SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2,
+    Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>& set_of_pairs)
+    -> bool {
+  if (specific_id1.index > specific_id2.index) {
+    std::swap(specific_id1.index, specific_id2.index);
+  }
+  auto insert_result =
+      set_of_pairs.Insert(std::make_pair(specific_id1, specific_id2));
+  return insert_result.is_inserted();
+}
+
+auto FileContext::ContainsPair(
+    SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2,
+    const Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>& set_of_pairs)
+    -> bool {
+  if (specific_id1.index > specific_id2.index) {
+    std::swap(specific_id1.index, specific_id2.index);
+  }
+  return set_of_pairs.Contains(std::make_pair(specific_id1, specific_id2));
+}
+
+auto FileContext::CoalesceEquivalentSpecifics() -> void {
+  for (auto& specifics : lowered_specifics_) {
+    // i cannot be unsigned due to the comparison with a negative number when
+    // the specifics vector is empty.
+    for (int i = 0; i < static_cast<int>(specifics.size()) - 1; ++i) {
+      // This specific was already replaced, skip it.
+      if (equivalent_specifics_[specifics[i].index].has_value() &&
+          equivalent_specifics_[specifics[i].index] != specifics[i]) {
+        specifics[i] = specifics[specifics.size() - 1];
+        specifics.pop_back();
+        --i;
+        continue;
+      }
+      // TODO: Improve quadratic behavior by using a single hash based on
+      // `lowered_specifics_type_fingerprint_` and `common_fingerprint`.
+      for (int j = i + 1; j < static_cast<int>(specifics.size()); ++j) {
+        // When the specific was already replaced, skip it.
+        if (equivalent_specifics_[specifics[j].index].has_value() &&
+            equivalent_specifics_[specifics[j].index] != specifics[j]) {
+          specifics[j] = specifics[specifics.size() - 1];
+          specifics.pop_back();
+          --j;
+          continue;
+        }
+
+        // When the two specifics are not equivalent due to the function type
+        // info stored in lowered_specifics_types, mark non-equivalance. This
+        // can be reused to short-cut another path and continue the search for
+        // other equivalences.
+        if (!AreFunctionTypesEquivalent(specifics[i], specifics[j])) {
+          InsertPair(specifics[i], specifics[j], non_equivalent_specifics_);
+          continue;
+        }
+
+        Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>
+            visited_equivalent_specifics;
+        InsertPair(specifics[i], specifics[j], visited_equivalent_specifics);
+        // Function type information matches; check usages inside the function
+        // body that are dependent on the specific. This information has been
+        // stored in lowered_states while lowering each function body.
+        if (AreFunctionBodiesEquivalent(specifics[i], specifics[j],
+                                        visited_equivalent_specifics)) {
+          // When processing equivalences, we may change the canonical specific
+          // multiple times, so we don't delete replaced specifics until the
+          // end.
+          llvm::SmallVector<SemIR::SpecificId> specifics_to_delete;
+          visited_equivalent_specifics.ForEach(
+              [&](std::pair<SemIR::SpecificId, SemIR::SpecificId>
+                      equivalent_entry) {
+                CARBON_VLOG("Found equivalent specifics: {0}, {1}",
+                            equivalent_entry.first, equivalent_entry.second);
+                ProcessSpecificEquivalence(equivalent_entry,
+                                           specifics_to_delete);
+              });
+
+          // Delete function bodies for already replaced functions.
+          for (auto specific_id : specifics_to_delete) {
+            specific_functions_[specific_id.index]->eraseFromParent();
+            specific_functions_[specific_id.index] =
+                specific_functions_[equivalent_specifics_[specific_id.index]
+                                        .index];
+          }
+
+          // Removed the replaced specific from the list of emitted specifics.
+          // Only the top level, since the others are somewhere else in the
+          // vector, they will be found and removed during processing.
+          specifics[j] = specifics[specifics.size() - 1];
+          specifics.pop_back();
+          --j;
+        } else {
+          // Only mark non-equivalence based on state for starting specifics.
+          InsertPair(specifics[i], specifics[j], non_equivalent_specifics_);
+        }
+      }
+    }
+  }
+}
+
+auto FileContext::ProcessSpecificEquivalence(
+    std::pair<SemIR::SpecificId, SemIR::SpecificId> pair,
+    llvm::SmallVector<SemIR::SpecificId>& specifics_to_delete) -> void {
+  auto [specific_id1, specific_id2] = pair;
+  CARBON_CHECK(specific_id1.has_value() && specific_id2.has_value(),
+               "Expected values in equivalence check");
+
+  auto get_canon = [&](SemIR::SpecificId specific_id) {
+    return equivalent_specifics_[specific_id.index].has_value()
+               ? std::make_pair(
+                     equivalent_specifics_[specific_id.index],
+                     (equivalent_specifics_[specific_id.index] != specific_id))
+               : std::make_pair(specific_id, false);
+  };
+  auto [canon_id1, replaced_before1] = get_canon(specific_id1);
+  auto [canon_id2, replaced_before2] = get_canon(specific_id2);
+
+  if (canon_id1 == canon_id2) {
+    // Already equivalent, there was a previous replacement.
+    return;
+  }
+
+  if (canon_id1.index >= canon_id2.index) {
+    // Prefer the earlier index for canonical values.
+    std::swap(canon_id1, canon_id2);
+    std::swap(replaced_before1, replaced_before2);
+  }
+
+  // Update equivalent_specifics_ for all. This is used as an indicator that
+  // this specific_id may be the canonical one when reducing the equivalence
+  // chains in `IsKnownEquivalence`.
+  equivalent_specifics_[specific_id1.index] = canon_id1;
+  equivalent_specifics_[specific_id2.index] = canon_id1;
+  specific_functions_[canon_id2.index]->replaceAllUsesWith(
+      specific_functions_[canon_id1.index]);
+  if (!replaced_before2) {
+    specifics_to_delete.push_back(canon_id2);
+  }
+}
+
+auto FileContext::IsKnownEquivalence(SemIR::SpecificId specific_id1,
+                                     SemIR::SpecificId specific_id2) -> bool {
+  if (!equivalent_specifics_[specific_id1.index].has_value() ||
+      !equivalent_specifics_[specific_id2.index].has_value()) {
+    return false;
+  }
+
+  auto update_equivalent_specific = [&](SemIR::SpecificId specific_id) {
+    llvm::SmallVector<SemIR::SpecificId> stack;
+    SemIR::SpecificId specific_to_update = specific_id;
+    while (equivalent_specifics_[equivalent_specifics_[specific_to_update.index]
+                                     .index] !=
+           equivalent_specifics_[specific_to_update.index]) {
+      stack.push_back(specific_to_update);
+      specific_to_update = equivalent_specifics_[specific_to_update.index];
+    }
+    for (auto specific : llvm::reverse(stack)) {
+      equivalent_specifics_[specific.index] =
+          equivalent_specifics_[equivalent_specifics_[specific.index].index];
+    }
+  };
+
+  update_equivalent_specific(specific_id1);
+  update_equivalent_specific(specific_id2);
+
+  return equivalent_specifics_[specific_id1.index] ==
+         equivalent_specifics_[specific_id2.index];
+}
+
+auto FileContext::AreFunctionTypesEquivalent(SemIR::SpecificId specific_id1,
+                                             SemIR::SpecificId specific_id2)
+    -> bool {
+  CARBON_CHECK(specific_id1.has_value() && specific_id2.has_value());
+  return lowered_specifics_type_fingerprint_[specific_id1.index] ==
+         lowered_specifics_type_fingerprint_[specific_id2.index];
+}
+
+auto FileContext::AreFunctionBodiesEquivalent(
+    SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2,
+    Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>&
+        visited_equivalent_specifics) -> bool {
+  llvm::SmallVector<std::pair<SemIR::SpecificId, SemIR::SpecificId>> worklist;
+  worklist.push_back({specific_id1, specific_id2});
+
+  while (!worklist.empty()) {
+    auto outer_pair = worklist.pop_back_val();
+    auto [specific_id1, specific_id2] = outer_pair;
+
+    auto state1 = lowered_specific_fingerprint_[specific_id1.index];
+    auto state2 = lowered_specific_fingerprint_[specific_id2.index];
+    if (state1.common_fingerprint != state2.common_fingerprint) {
+      InsertPair(specific_id1, specific_id2, non_equivalent_specifics_);
+      return false;
+    }
+    if (state1.specific_fingerprint == state2.specific_fingerprint) {
+      continue;
+    }
+
+    // A size difference should have been detected by the common fingerprint.
+    CARBON_CHECK(state1.calls.size() == state2.calls.size(),
+                 "Number of specific calls expected to be the same.");
+
+    for (auto [state1_call, state2_call] :
+         llvm::zip(state1.calls, state2.calls)) {
+      if (state1_call != state2_call) {
+        if (ContainsPair(state1_call, state2_call, non_equivalent_specifics_)) {
+          return false;
+        }
+        if (IsKnownEquivalence(state1_call, state2_call)) {
+          continue;
+        }
+        if (!InsertPair(state1_call, state2_call,
+                        visited_equivalent_specifics)) {
+          continue;
+        }
+        // Leave the added equivalence pair in place and continue.
+        worklist.push_back({state1_call, state2_call});
+      }
+    }
+  }
+  return true;
+}
+
 auto FileContext::BuildDICompileUnit(llvm::StringRef module_name,
                                      llvm::Module& llvm_module,
                                      llvm::DIBuilder& di_builder)
@@ -407,6 +644,19 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id,
   Mangler m(*this);
   std::string mangled_name = m.Mangle(function_id, specific_id);
 
+  // Create a unique fingerprint for the function type.
+  // For now, compute the function type fingerprint only for specifics, though
+  // we might need it for all functions in order to create a canonical
+  // fingerprint across translation units.
+  if (specific_id.has_value()) {
+    llvm::BLAKE3 function_type_fingerprint;
+    RawStringOstream os;
+    function_type_info.type->print(os);
+    function_type_fingerprint.update(os.TakeStr());
+    function_type_fingerprint.final(
+        lowered_specifics_type_fingerprint_[specific_id.index]);
+  }
+
   auto* llvm_function = llvm::Function::Create(function_type_info.type, linkage,
                                                mangled_name, llvm_module());
 
@@ -491,9 +741,16 @@ auto FileContext::BuildFunctionBody(SemIR::FunctionId function_id,
   CARBON_DCHECK(!body_block_ids.empty(),
                 "No function body blocks found during lowering.");
 
-  FunctionContext function_lowering(*this, llvm_function, specific_id,
-                                    BuildDISubprogram(function, llvm_function),
-                                    vlog_stream_);
+  // Store which specifics were already lowered (with definitions) for each
+  // generic.
+  if (function.generic_id.has_value() && specific_id.has_value()) {
+    AddLoweredSpecificForGeneric(function.generic_id, specific_id);
+  }
+
+  FunctionContext function_lowering(
+      *this, llvm_function, specific_id,
+      InitializeFingerprintForSpecific(specific_id),
+      BuildDISubprogram(function, llvm_function), vlog_stream_);
 
   // Add parameters to locals.
   // TODO: This duplicates the mapping between sem_ir instructions and LLVM
@@ -593,6 +850,9 @@ auto FileContext::BuildFunctionBody(SemIR::FunctionId function_id,
         llvm_context(), "entry", llvm_function, entry_block);
     llvm::BranchInst::Create(entry_block, new_entry_block);
   }
+
+  // Emit fingerprint accumulated inside the function context.
+  function_lowering.EmitFinalFingerprint();
 }
 
 auto FileContext::BuildDISubprogram(const SemIR::Function& function,

+ 120 - 0
toolchain/lower/file_context.h

@@ -8,10 +8,13 @@
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/CodeGen/ModuleBuilder.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "common/raw_string_ostream.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Support/BLAKE3.h"
 #include "toolchain/parse/tree_and_subtrees.h"
 #include "toolchain/sem_ir/file.h"
 #include "toolchain/sem_ir/ids.h"
@@ -31,6 +34,22 @@ class FileContext {
     int32_t column_number;
   };
 
+  // Describes a specific function's body fingerprint.
+  struct SpecificFunctionFingerprint {
+    // Fingerprint with all specific-dependent instructions, except specific
+    // calls. This is built by the `FunctionContext` while lowering each
+    // instruction in the definition of a specific function.
+    // TODO: This can be merged with the function type fingerprint, for a
+    // single upfront non-equivalence check, and hash bucketing for deeper
+    // equivalence evaluation.
+    llvm::BLAKE3Result<32> common_fingerprint;
+    // Fingerprint for all calls to specific functions (hashes all calls to
+    // other specifics). This is built by the `FunctionContext` while lowering.
+    llvm::BLAKE3Result<32> specific_fingerprint;
+    // All non-hashed specific_ids of functions called.
+    llvm::SmallVector<SemIR::SpecificId> calls;
+  };
+
   explicit FileContext(
       llvm::LLVMContext& llvm_context,
       llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
@@ -167,6 +186,73 @@ class FileContext {
 
   auto BuildVtable(const SemIR::Class& class_info) -> llvm::GlobalVariable*;
 
+  // Records a specific that was lowered for a generic. These are added one
+  // by one while lowering their definitions.
+  auto AddLoweredSpecificForGeneric(SemIR::GenericId generic_id,
+                                    SemIR::SpecificId specific_id) {
+    lowered_specifics_[generic_id.index].push_back(specific_id);
+  }
+
+  // Initializes and returns a SpecificFunctionFingerprint* instance for a
+  // specific. The internal of the fingerprint are populated during and after
+  // lowering the function body of that specific.
+  auto InitializeFingerprintForSpecific(SemIR::SpecificId specific_id)
+      -> SpecificFunctionFingerprint* {
+    if (!specific_id.has_value()) {
+      return nullptr;
+    }
+    return &lowered_specific_fingerprint_[specific_id.index];
+  }
+
+  // Entry point for coalescing equivalent specifics. Two function definitions,
+  // from the same generic, with different specific_ids are considered
+  // equivalent if, at the LLVM level, one can be replaced with the other, with
+  // no change in behavior. All LLVM types and instructions must be equivalent.
+  auto CoalesceEquivalentSpecifics() -> void;
+
+  // While coalescing specifics, returns whether the function types for two
+  // specifics are equivalent. This uses a fingerprint generated for each
+  // function type.
+  auto AreFunctionTypesEquivalent(SemIR::SpecificId specific_id1,
+                                  SemIR::SpecificId specific_id2) -> bool;
+
+  // While coalescing specifics, compare the function bodies for two specifics.
+  // This uses fingerprints generated during lowering of the function body.
+  // The `visited_equivalent_specifics` parameter is used to track cycles in
+  // the function callgraph, and will also return equivalent pairs of specifics
+  // found, if the two specifics given as arguments are found to be equivalent.
+  auto AreFunctionBodiesEquivalent(
+      SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2,
+      Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>&
+          visited_equivalent_specifics) -> bool;
+
+  // Given an equivalent pair of specifics, updates the canonical specific to
+  // use for each of the two Specifics found to be equivalent, replaces all
+  // uses of one specific with the canonical one, and adds the non-canonical
+  // specific to specifics_to_delete.
+  auto ProcessSpecificEquivalence(
+      std::pair<SemIR::SpecificId, SemIR::SpecificId> pair,
+      llvm::SmallVector<SemIR::SpecificId>& specifics_to_delete) -> void;
+
+  // Checks if two specific_ids are equivalent and also reduces the equivalence
+  // chains/paths. This update ensures the canonical specific is always "one
+  // hop away".
+  auto IsKnownEquivalence(SemIR::SpecificId specific_id1,
+                          SemIR::SpecificId specific_id2) -> bool;
+
+  // Inserts a pair into a set of pairs in canonical form. Also implicitly
+  // checks entry already existed if it cannot be inserted.
+  auto InsertPair(
+      SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2,
+      Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>& set_of_pairs)
+      -> bool;
+
+  // Checks if a pair is contained into a set of pairs, in canonical form.
+  auto ContainsPair(
+      SemIR::SpecificId specific_id1, SemIR::SpecificId specific_id2,
+      const Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>& set_of_pairs)
+      -> bool;
+
   // State for building the LLVM IR.
   llvm::LLVMContext* llvm_context_;
   std::unique_ptr<llvm::Module> llvm_module_;
@@ -242,6 +328,40 @@ class FileContext {
 
   // Global format string for `printf.int.format` used by the PrintInt builtin.
   llvm::Value* printf_int_format_string_ = nullptr;
+
+  // For a generic function, keep track of the specifics for which LLVM
+  // function declarations were created. Those can be retrieved then from
+  // `specific_functions_`. We resize this to the correct size. Vector indexes
+  // correspond to `GenericId` indexes.
+  llvm::SmallVector<llvm::SmallVector<SemIR::SpecificId>, 0> lowered_specifics_;
+
+  // For specifics that exist in lowered_specifics, a hash of their function
+  // type information: return and parameter types. We resize this to the
+  // correct size. Vector indexes correspond to `SpecificId` indexes.
+  // TODO: Hashing all members of `FunctionTypeInfo` may not be necessary.
+  llvm::SmallVector<llvm::BLAKE3Result<32>, 0>
+      lowered_specifics_type_fingerprint_;
+
+  // This is initialized and populated while lowering a specific.
+  // We resize this to the correct size. Vector indexes correspond to
+  // `SpecificId` indexes.
+  llvm::SmallVector<SpecificFunctionFingerprint, 0>
+      lowered_specific_fingerprint_;
+
+  // Equivalent specifics that have been found. For each specific, this points
+  // to the canonical equivalent specific, which may also be self. We currently
+  // define the canonical specific as the one with the lowest
+  // `SpecificId.index`.
+  //
+  // We resize this to the correct size and initialize to `SpecificId::None`,
+  // which defines that there is no other equivalent specific to this
+  // `SpecificId`. Vector indexes correspond to `SpecificId` indexes.
+  llvm::SmallVector<SemIR::SpecificId, 0> equivalent_specifics_;
+
+  // Non-equivalent specifics found.
+  // TODO: Revisit this due to its quadratic space growth.
+  Set<std::pair<SemIR::SpecificId, SemIR::SpecificId>>
+      non_equivalent_specifics_;
 };
 
 }  // namespace Carbon::Lower

+ 81 - 6
toolchain/lower/function_context.cpp

@@ -11,18 +11,19 @@
 
 namespace Carbon::Lower {
 
-FunctionContext::FunctionContext(FileContext& file_context,
-                                 llvm::Function* function,
-                                 SemIR::SpecificId specific_id,
-                                 llvm::DISubprogram* di_subprogram,
-                                 llvm::raw_ostream* vlog_stream)
+FunctionContext::FunctionContext(
+    FileContext& file_context, llvm::Function* function,
+    SemIR::SpecificId specific_id,
+    FileContext::SpecificFunctionFingerprint* function_fingerprint,
+    llvm::DISubprogram* di_subprogram, llvm::raw_ostream* vlog_stream)
     : file_context_(&file_context),
       function_(function),
       specific_id_(specific_id),
       builder_(file_context.llvm_context(), llvm::ConstantFolder(),
                Inserter(file_context.inst_namer())),
       di_subprogram_(di_subprogram),
-      vlog_stream_(vlog_stream) {
+      vlog_stream_(vlog_stream),
+      function_fingerprint_(function_fingerprint) {
   function_->setSubprogram(di_subprogram_);
 }
 
@@ -143,6 +144,25 @@ auto FunctionContext::GetBlockArg(SemIR::InstBlockId block_id,
   return phi;
 }
 
+auto FunctionContext::GetValue(SemIR::InstId inst_id) -> llvm::Value* {
+  // All builtins are types, with the same empty lowered value.
+  if (SemIR::IsSingletonInstId(inst_id)) {
+    return GetTypeAsValue();
+  }
+
+  if (auto result = locals_.Lookup(inst_id)) {
+    return result.value();
+  }
+
+  if (auto result = file_context_->global_variables().Lookup(inst_id)) {
+    return result.value();
+  }
+
+  auto* global = file_context_->GetGlobal(inst_id, specific_id_);
+  AddGlobalToCurrentFingerprint(global);
+  return global;
+}
+
 auto FunctionContext::MakeSyntheticBlock() -> llvm::BasicBlock* {
   synthetic_block_ = llvm::BasicBlock::Create(llvm_context(), "", function_);
   return synthetic_block_;
@@ -240,4 +260,59 @@ auto FunctionContext::Inserter::InsertHelper(
                                          insert_pt);
 }
 
+auto FunctionContext::AddCallToCurrentFingerprint(SemIR::FunctionId function_id,
+                                                  SemIR::SpecificId specific_id)
+    -> void {
+  if (!function_fingerprint_) {
+    return;
+  }
+
+  RawStringOstream os;
+  // TODO: Replace index with info that is translation unit independent.
+  // Using a string that includes the `FunctionId` string and the index to
+  // avoid possible collisions. This needs revisiting.
+  os << "function_id" << function_id.index << "\n";
+  current_fingerprint_.common_fingerprint.update(os.TakeStr());
+  // TODO: Replace index with info that is translation unit independent.
+  if (specific_id.has_value()) {
+    current_fingerprint_.specific_fingerprint.update(specific_id.index);
+    // TODO: Uses -1 as delimiter. This needs revisiting.
+    current_fingerprint_.specific_fingerprint.update(-1);
+    function_fingerprint_->calls.push_back(specific_id);
+  }
+}
+
+auto FunctionContext::AddTypeToCurrentFingerprint(llvm::Type* type) -> void {
+  if (!function_fingerprint_ || !type) {
+    return;
+  }
+
+  RawStringOstream os;
+  type->print(os);
+  os << "\n";
+  current_fingerprint_.common_fingerprint.update(os.TakeStr());
+}
+
+auto FunctionContext::AddGlobalToCurrentFingerprint(llvm::Value* global)
+    -> void {
+  if (!function_fingerprint_ || !global) {
+    return;
+  }
+
+  RawStringOstream os;
+  global->print(os);
+  os << "\n";
+  current_fingerprint_.common_fingerprint.update(os.TakeStr());
+}
+
+auto FunctionContext::EmitFinalFingerprint() -> void {
+  if (!function_fingerprint_) {
+    return;
+  }
+  current_fingerprint_.common_fingerprint.final(
+      function_fingerprint_->common_fingerprint);
+  current_fingerprint_.specific_fingerprint.final(
+      function_fingerprint_->specific_fingerprint);
+}
+
 }  // namespace Carbon::Lower

+ 57 - 20
toolchain/lower/function_context.h

@@ -6,6 +6,7 @@
 #define CARBON_TOOLCHAIN_LOWER_FUNCTION_CONTEXT_H_
 
 #include "common/map.h"
+#include "common/raw_string_ostream.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
@@ -18,10 +19,37 @@ namespace Carbon::Lower {
 // `llvm::Function` definition.
 class FunctionContext {
  public:
-  explicit FunctionContext(FileContext& file_context, llvm::Function* function,
-                           SemIR::SpecificId specific_id,
-                           llvm::DISubprogram* di_subprogram,
-                           llvm::raw_ostream* vlog_stream);
+  // `function` must not be null. `function_fingerprint` and `di_subprogram` may
+  // be null (see members).
+  explicit FunctionContext(
+      FileContext& file_context, llvm::Function* function,
+      SemIR::SpecificId specific_id,
+      FileContext::SpecificFunctionFingerprint* function_fingerprint,
+      llvm::DISubprogram* di_subprogram, llvm::raw_ostream* vlog_stream);
+
+  // Describes a function's body fingerprint while creating the function body.
+  // The final fingerprint is stored in the `FileContext` as a
+  // `SpecificFunctionFingerprint`.
+  //
+  // Create two function fingerprints, where both fingerprints include data
+  // that's evaluated (and hence lowered) differently based on the
+  // `SpecificId`. `common_fingerprint` includes global values, types
+  // and `FunctionId` for functions called inside the function body.
+  // `specific_fingerprint` includes `SpecificId`s for functions called.
+  //
+  // For two specifics of the same generic:
+  // - If `common_fingerprint` is different, the specifics cannot be coalesced.
+  // - If `common_fingerprint` and `specific_fingerprint` are the
+  //   same, the specifics can be coalesced without additional checks.
+  // - If `common_fingerprint` is the same but `specific_fingerprint` is
+  //   different, additional checks are needed, i.e. inspecting the non-hashed
+  //   `SpecificId`s.
+  //
+  // TODO: Consider optimizations for repeated entries in both fingerprints.
+  struct LoweringFunctionFingerprint {
+    llvm::BLAKE3 common_fingerprint;
+    llvm::BLAKE3 specific_fingerprint;
+  };
 
   // Returns a basic block corresponding to the start of the given semantics
   // block, and enqueues it for emission.
@@ -45,22 +73,7 @@ class FunctionContext {
       -> llvm::PHINode*;
 
   // Returns a value for the given instruction.
-  auto GetValue(SemIR::InstId inst_id) -> llvm::Value* {
-    // All builtins are types, with the same empty lowered value.
-    if (SemIR::IsSingletonInstId(inst_id)) {
-      return GetTypeAsValue();
-    }
-
-    if (auto result = locals_.Lookup(inst_id)) {
-      return result.value();
-    }
-
-    if (auto result = file_context_->global_variables().Lookup(inst_id)) {
-      return result.value();
-    }
-
-    return file_context_->GetGlobal(inst_id, specific_id_);
-  }
+  auto GetValue(SemIR::InstId inst_id) -> llvm::Value*;
 
   // Sets the value for the given instruction.
   auto SetLocal(SemIR::InstId inst_id, llvm::Value* value) -> void {
@@ -139,6 +152,18 @@ class FunctionContext {
   auto FinishInit(SemIR::TypeId type_id, SemIR::InstId dest_id,
                   SemIR::InstId source_id) -> void;
 
+  // When fingerprinting for a specific, adds the call, found in the function
+  // body, to <function_id, specific_id>.
+  auto AddCallToCurrentFingerprint(SemIR::FunctionId function_id,
+                                   SemIR::SpecificId specific_id) -> void;
+
+  // When fingerprinting for a specific, adds the type.
+  auto AddTypeToCurrentFingerprint(llvm::Type* type) -> void;
+
+  // Emits the final function fingerprints. Only called when function lowering
+  // is complete.
+  auto EmitFinalFingerprint() -> void;
+
   auto llvm_context() -> llvm::LLVMContext& {
     return file_context_->llvm_context();
   }
@@ -194,6 +219,9 @@ class FunctionContext {
   auto CopyObject(SemIR::TypeId type_id, SemIR::InstId source_id,
                   SemIR::InstId dest_id) -> void;
 
+  // When fingerprinting for a specific, adds the global.
+  auto AddGlobalToCurrentFingerprint(llvm::Value* global) -> void;
+
   // Context for the overall lowering process.
   FileContext* file_context_;
 
@@ -216,6 +244,15 @@ class FunctionContext {
   // The optional vlog stream.
   llvm::raw_ostream* vlog_stream_;
 
+  // This is initialized and populated while lowering a specific function.
+  // When complete, this is used to complete the function_fingerprint_.
+  LoweringFunctionFingerprint current_fingerprint_;
+
+  // The accumulated fingerprint is owned by the FileContext and passed into
+  // the FunctionContext. The function fingerprint is currently only built for
+  // specific functions, otherwise, this will be nullptr.
+  FileContext::SpecificFunctionFingerprint* function_fingerprint_;
+
   // Maps a function's SemIR::File blocks to lowered blocks.
   Map<SemIR::InstBlockId, llvm::BasicBlock*> blocks_;
 

+ 1 - 0
toolchain/lower/handle.cpp

@@ -288,6 +288,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
                 SemIR::VarStorage /* inst */) -> void {
   auto* type = context.GetType(SemIR::GetTypeOfInstInSpecific(
       context.sem_ir(), context.specific_id(), inst_id));
+  context.AddTypeToCurrentFingerprint(type);
 
   // Position the first alloca right before the start of the executable code in
   // the function.

+ 2 - 0
toolchain/lower/handle_call.cpp

@@ -482,6 +482,8 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
 
   const SemIR::Function& function =
       context.sem_ir().functions().Get(callee_function.function_id);
+  context.AddCallToCurrentFingerprint(callee_function.function_id,
+                                      callee_function.resolved_specific_id);
 
   if (auto builtin_kind = function.builtin_function_kind;
       builtin_kind != SemIR::BuiltinFunctionKind::None) {

+ 2 - 0
toolchain/lower/handle_expr_category.cpp

@@ -25,6 +25,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
     case SemIR::ValueRepr::Copy: {
       auto* type = context.GetType(SemIR::GetTypeOfInstInSpecific(
           context.sem_ir(), context.specific_id(), inst_id));
+      context.AddTypeToCurrentFingerprint(type);
       context.SetLocal(inst_id, context.builder().CreateLoad(
                                     type, context.GetValue(inst.value_id)));
     } break;
@@ -46,6 +47,7 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
                 SemIR::TemporaryStorage /*inst*/) -> void {
   auto* type = context.GetType(SemIR::GetTypeOfInstInSpecific(
       context.sem_ir(), context.specific_id(), inst_id));
+  context.AddTypeToCurrentFingerprint(type);
   context.SetLocal(inst_id,
                    context.builder().CreateAlloca(type, nullptr, "temp"));
 }

+ 8 - 14
toolchain/lower/testdata/function/generic/call.carbon

@@ -50,7 +50,7 @@ fn G() {
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %m.var), !dbg !10
 // CHECK:STDOUT:   store double 0.000000e+00, ptr %m.var, align 8, !dbg !10
 // CHECK:STDOUT:   call void @_CF.Main.15b1f98bd9cc0c5b(ptr %c.var), !dbg !11
-// CHECK:STDOUT:   call void @_CF.Main.2cc450fc05045897(ptr %d.var), !dbg !12
+// CHECK:STDOUT:   call void @_CF.Main.15b1f98bd9cc0c5b(ptr %d.var), !dbg !12
 // CHECK:STDOUT:   %.loc25 = load i32, ptr %n.var, align 4, !dbg !13
 // CHECK:STDOUT:   call void @_CF.Main.b88d1103f417c6d4(i32 %.loc25), !dbg !14
 // CHECK:STDOUT:   %.loc26 = load double, ptr %m.var, align 8, !dbg !15
@@ -70,29 +70,25 @@ fn G() {
 // CHECK:STDOUT:   ret void, !dbg !20
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CF.Main.2cc450fc05045897(ptr %x) !dbg !21 {
+// CHECK:STDOUT: define linkonce_odr void @_CF.Main.b88d1103f417c6d4(i32 %x) !dbg !21 {
 // CHECK:STDOUT: entry:
 // CHECK:STDOUT:   ret void, !dbg !22
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CF.Main.b88d1103f417c6d4(i32 %x) !dbg !23 {
+// CHECK:STDOUT: define linkonce_odr void @_CF.Main.66be507887ceee78(double %x) !dbg !23 {
 // CHECK:STDOUT: entry:
 // CHECK:STDOUT:   ret void, !dbg !24
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CF.Main.66be507887ceee78(double %x) !dbg !25 {
+// CHECK:STDOUT: define linkonce_odr void @_CF.Main.5754c7a55c7cbe4a(%type %x) !dbg !25 {
 // CHECK:STDOUT: entry:
 // CHECK:STDOUT:   ret void, !dbg !26
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CF.Main.5754c7a55c7cbe4a(%type %x) !dbg !27 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret void, !dbg !28
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @llvm.memcpy.p0.p0.i64, { 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.15b1f98bd9cc0c5b, { 1, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT: attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
@@ -121,11 +117,9 @@ fn G() {
 // CHECK:STDOUT: !18 = !DILocation(line: 17, column: 1, scope: !4)
 // CHECK:STDOUT: !19 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.15b1f98bd9cc0c5b", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !20 = !DILocation(line: 11, column: 1, scope: !19)
-// CHECK:STDOUT: !21 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.2cc450fc05045897", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !21 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !22 = !DILocation(line: 11, column: 1, scope: !21)
-// CHECK:STDOUT: !23 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !23 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !24 = !DILocation(line: 11, column: 1, scope: !23)
-// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !25 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !26 = !DILocation(line: 11, column: 1, scope: !25)
-// CHECK:STDOUT: !27 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !28 = !DILocation(line: 11, column: 1, scope: !27)

+ 7 - 23
toolchain/lower/testdata/function/generic/call_basic.carbon

@@ -110,10 +110,10 @@ fn M() {
 // CHECK:STDOUT:   %H.call.loc32 = call ptr @_CH.Main.e8193710fd35b608(ptr %.loc32), !dbg !38
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !27
 // CHECK:STDOUT:   %.loc34 = load ptr, ptr %ptr_f64.var, align 8, !dbg !39
-// CHECK:STDOUT:   %H.call.loc34 = call ptr @_CH.Main.04bf2edaaa84aa22(ptr %.loc34), !dbg !40
+// CHECK:STDOUT:   %H.call.loc34 = call ptr @_CH.Main.e8193710fd35b608(ptr %.loc34), !dbg !40
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i8.var), !dbg !28
 // CHECK:STDOUT:   %.loc36 = load ptr, ptr %ptr_i8.var, align 8, !dbg !41
-// CHECK:STDOUT:   %H.call.loc36 = call ptr @_CH.Main.bda010de15e6a5ad(ptr %.loc36), !dbg !42
+// CHECK:STDOUT:   %H.call.loc36 = call ptr @_CH.Main.e8193710fd35b608(ptr %.loc36), !dbg !42
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !29
 // CHECK:STDOUT:   %.loc38_6.1.temp = alloca {}, align 8, !dbg !43
 // CHECK:STDOUT:   call void @_CH.Main.15b1f98bd9cc0c5b(ptr %.loc38_6.1.temp, ptr %c.var), !dbg !43
@@ -145,10 +145,10 @@ fn M() {
 // CHECK:STDOUT:   %H.call.loc32 = call ptr @_CH.Main.e8193710fd35b608(ptr %.loc32), !dbg !61
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !50
 // CHECK:STDOUT:   %.loc34 = load ptr, ptr %ptr_f64.var, align 8, !dbg !62
-// CHECK:STDOUT:   %H.call.loc34 = call ptr @_CH.Main.04bf2edaaa84aa22(ptr %.loc34), !dbg !63
+// CHECK:STDOUT:   %H.call.loc34 = call ptr @_CH.Main.e8193710fd35b608(ptr %.loc34), !dbg !63
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i8.var), !dbg !51
 // CHECK:STDOUT:   %.loc36 = load ptr, ptr %ptr_i8.var, align 8, !dbg !64
-// CHECK:STDOUT:   %H.call.loc36 = call ptr @_CH.Main.bda010de15e6a5ad(ptr %.loc36), !dbg !65
+// CHECK:STDOUT:   %H.call.loc36 = call ptr @_CH.Main.e8193710fd35b608(ptr %.loc36), !dbg !65
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !52
 // CHECK:STDOUT:   %.loc38_6.1.temp = alloca {}, align 8, !dbg !66
 // CHECK:STDOUT:   call void @_CH.Main.15b1f98bd9cc0c5b(ptr %.loc38_6.1.temp, ptr %c.var), !dbg !66
@@ -175,29 +175,17 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %x, !dbg !75
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CH.Main.04bf2edaaa84aa22(ptr %x) !dbg !76 {
+// CHECK:STDOUT: define linkonce_odr void @_CH.Main.15b1f98bd9cc0c5b(ptr sret({}) %return, ptr %x) !dbg !76 {
 // CHECK:STDOUT: entry:
 // CHECK:STDOUT:   ret ptr %x, !dbg !77
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CH.Main.bda010de15e6a5ad(ptr %x) !dbg !78 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !79
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CH.Main.15b1f98bd9cc0c5b(ptr sret({}) %return, ptr %x) !dbg !80 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !81
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 13, 12, 11, 10 }
 // CHECK:STDOUT: uselistorder ptr @_CH.Main.b88d1103f417c6d4, { 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CH.Main.5754c7a55c7cbe4a, { 3, 2, 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CH.Main.66be507887ceee78, { 3, 2, 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @_CH.Main.e8193710fd35b608, { 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @_CH.Main.04bf2edaaa84aa22, { 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @_CH.Main.bda010de15e6a5ad, { 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CH.Main.e8193710fd35b608, { 5, 2, 0, 4, 3, 1 }
 // CHECK:STDOUT: uselistorder ptr @_CH.Main.15b1f98bd9cc0c5b, { 1, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
@@ -281,9 +269,5 @@ fn M() {
 // CHECK:STDOUT: !73 = !DILocation(line: 17, column: 3, scope: !72)
 // CHECK:STDOUT: !74 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.e8193710fd35b608", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !75 = !DILocation(line: 17, column: 3, scope: !74)
-// CHECK:STDOUT: !76 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !76 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.15b1f98bd9cc0c5b", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !77 = !DILocation(line: 17, column: 3, scope: !76)
-// CHECK:STDOUT: !78 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.bda010de15e6a5ad", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !79 = !DILocation(line: 17, column: 3, scope: !78)
-// CHECK:STDOUT: !80 = distinct !DISubprogram(name: "H", linkageName: "_CH.Main.15b1f98bd9cc0c5b", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !81 = !DILocation(line: 17, column: 3, scope: !80)

+ 3 - 16
toolchain/lower/testdata/function/generic/call_dedup_ptr.carbon

@@ -37,10 +37,10 @@ fn M() {
 // CHECK:STDOUT:   %F.call.loc20 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc20), !dbg !11
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !8
 // CHECK:STDOUT:   %.loc22 = load ptr, ptr %ptr_f64.var, align 8, !dbg !12
-// CHECK:STDOUT:   %F.call.loc22 = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %.loc22), !dbg !13
+// CHECK:STDOUT:   %F.call.loc22 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc22), !dbg !13
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i8.var), !dbg !9
 // CHECK:STDOUT:   %.loc24 = load ptr, ptr %ptr_i8.var, align 8, !dbg !14
-// CHECK:STDOUT:   %F.call.loc24 = call ptr @_CF.Main.bda010de15e6a5ad(ptr %.loc24), !dbg !15
+// CHECK:STDOUT:   %F.call.loc24 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc24), !dbg !15
 // CHECK:STDOUT:   ret void, !dbg !16
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -52,18 +52,9 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %x, !dbg !18
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.04bf2edaaa84aa22(ptr %x) !dbg !19 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !20
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.bda010de15e6a5ad(ptr %x) !dbg !21 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !22
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.e8193710fd35b608, { 2, 1, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT:
@@ -89,7 +80,3 @@ fn M() {
 // CHECK:STDOUT: !16 = !DILocation(line: 15, column: 1, scope: !4)
 // CHECK:STDOUT: !17 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.e8193710fd35b608", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !18 = !DILocation(line: 12, column: 3, scope: !17)
-// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !20 = !DILocation(line: 12, column: 3, scope: !19)
-// CHECK:STDOUT: !21 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.bda010de15e6a5ad", scope: null, file: !3, line: 11, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !22 = !DILocation(line: 12, column: 3, scope: !21)

+ 112 - 0
toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon

@@ -0,0 +1,112 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_different_impls_with_const.carbon
+
+import Core library "io";
+
+interface I {
+  let T:! type;
+  fn F() -> T;
+}
+class X {}
+impl X as I where .T = bool {
+  fn F() -> bool {
+    Core.Print(1);
+    return false;
+  }
+}
+class Y {}
+impl Y as I where .T = i32 {
+  fn F() -> i32 {
+    Core.Print(2);
+    return 2;
+  }
+}
+
+// Cannot coalesce the lowering for G specifics, as they call different functions.
+// Check different functions are still emitted when trying to deduplicate emitted definitons.
+fn G(U:! I) {
+  let x: U.T = U.F();
+}
+
+fn Run() {
+  G(X);
+  G(Y);
+}
+
+// CHECK:STDOUT: ; ModuleID = 'call_different_impls_with_const.carbon'
+// CHECK:STDOUT: source_filename = "call_different_impls_with_const.carbon"
+// CHECK:STDOUT:
+// CHECK:STDOUT: @printf.int.format = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
+// CHECK:STDOUT:
+// CHECK:STDOUT: define i1 @"_CF.X.Main:I.Main"() !dbg !4 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !7
+// CHECK:STDOUT:   ret i1 false, !dbg !8
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define i32 @"_CF.Y.Main:I.Main"() !dbg !9 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !10
+// CHECK:STDOUT:   ret i32 2, !dbg !11
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define void @main() !dbg !12 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   call void @_CG.Main.ae78220c5e9d4af5(), !dbg !13
+// CHECK:STDOUT:   call void @_CG.Main.6b293b16be321a45(), !dbg !14
+// CHECK:STDOUT:   ret void, !dbg !15
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: declare i32 @printf(ptr, ...)
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr void @_CG.Main.ae78220c5e9d4af5() !dbg !16 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %.loc35_20.1 = call i1 @"_CF.X.Main:I.Main"(), !dbg !17
+// CHECK:STDOUT:   %.loc35_20.2.temp = alloca i1, align 1, !dbg !17
+// CHECK:STDOUT:   store i1 %.loc35_20.1, ptr %.loc35_20.2.temp, align 1, !dbg !17
+// CHECK:STDOUT:   ret void, !dbg !18
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr void @_CG.Main.6b293b16be321a45() !dbg !19 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %.loc35_20.1 = call i32 @"_CF.Y.Main:I.Main"(), !dbg !20
+// CHECK:STDOUT:   %.loc35_20.2.temp = alloca i32, align 4, !dbg !20
+// CHECK:STDOUT:   store i32 %.loc35_20.1, ptr %.loc35_20.2.temp, align 4, !dbg !20
+// CHECK:STDOUT:   ret void, !dbg !21
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; uselistorder directives
+// CHECK:STDOUT: uselistorder ptr @printf, { 1, 0 }
+// CHECK:STDOUT:
+// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
+// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
+// CHECK:STDOUT:
+// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
+// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
+// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+// CHECK:STDOUT: !3 = !DIFile(filename: "call_different_impls_with_const.carbon", directory: "")
+// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "F", linkageName: "_CF.X.Main:I.Main", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
+// CHECK:STDOUT: !6 = !{}
+// CHECK:STDOUT: !7 = !DILocation(line: 20, column: 5, scope: !4)
+// CHECK:STDOUT: !8 = !DILocation(line: 21, column: 5, scope: !4)
+// CHECK:STDOUT: !9 = distinct !DISubprogram(name: "F", linkageName: "_CF.Y.Main:I.Main", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !10 = !DILocation(line: 27, column: 5, scope: !9)
+// CHECK:STDOUT: !11 = !DILocation(line: 28, column: 5, scope: !9)
+// CHECK:STDOUT: !12 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !13 = !DILocation(line: 39, column: 3, scope: !12)
+// CHECK:STDOUT: !14 = !DILocation(line: 40, column: 3, scope: !12)
+// CHECK:STDOUT: !15 = !DILocation(line: 38, column: 1, scope: !12)
+// CHECK:STDOUT: !16 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.ae78220c5e9d4af5", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !17 = !DILocation(line: 35, column: 16, scope: !16)
+// CHECK:STDOUT: !18 = !DILocation(line: 34, column: 1, scope: !16)
+// CHECK:STDOUT: !19 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.6b293b16be321a45", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !20 = !DILocation(line: 35, column: 16, scope: !19)
+// CHECK:STDOUT: !21 = !DILocation(line: 34, column: 1, scope: !19)

+ 2 - 22
toolchain/lower/testdata/function/generic/call_recursive_basic.carbon

@@ -59,7 +59,7 @@ fn M() {
 // CHECK:STDOUT:   %.loc30_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15
 // CHECK:STDOUT:   %F.call.loc30 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc30_5, i32 0), !dbg !16
 // CHECK:STDOUT:   %.loc31_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17
-// CHECK:STDOUT:   %F.call.loc31 = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %.loc31_5, i32 0), !dbg !18
+// CHECK:STDOUT:   %F.call.loc31 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc31_5, i32 0), !dbg !18
 // CHECK:STDOUT:   ret void, !dbg !19
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -108,22 +108,9 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %F.call, !dbg !40
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !41 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 0, !dbg !42
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !43
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !44
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else:                                          ; preds = %entry
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !45
-// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %x, i32 %int.sadd), !dbg !46
-// CHECK:STDOUT:   ret ptr %F.call, !dbg !47
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.e8193710fd35b608, { 1, 2, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT:
@@ -171,10 +158,3 @@ fn M() {
 // CHECK:STDOUT: !38 = !DILocation(line: 19, column: 15, scope: !34)
 // CHECK:STDOUT: !39 = !DILocation(line: 19, column: 10, scope: !34)
 // CHECK:STDOUT: !40 = !DILocation(line: 19, column: 3, scope: !34)
-// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 15, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !42 = !DILocation(line: 16, column: 7, scope: !41)
-// CHECK:STDOUT: !43 = !DILocation(line: 16, column: 6, scope: !41)
-// CHECK:STDOUT: !44 = !DILocation(line: 17, column: 5, scope: !41)
-// CHECK:STDOUT: !45 = !DILocation(line: 19, column: 15, scope: !41)
-// CHECK:STDOUT: !46 = !DILocation(line: 19, column: 10, scope: !41)
-// CHECK:STDOUT: !47 = !DILocation(line: 19, column: 3, scope: !41)

+ 75 - 140
toolchain/lower/testdata/function/generic/call_recursive_diamond.carbon

@@ -78,7 +78,7 @@ fn M() {
 // CHECK:STDOUT:   %.loc53_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15
 // CHECK:STDOUT:   %A.call.loc53 = call ptr @_CA.Main.e8193710fd35b608(ptr %.loc53_5, i32 0), !dbg !16
 // CHECK:STDOUT:   %.loc54_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17
-// CHECK:STDOUT:   %A.call.loc54 = call ptr @_CA.Main.04bf2edaaa84aa22(ptr %.loc54_5, i32 0), !dbg !18
+// CHECK:STDOUT:   %A.call.loc54 = call ptr @_CA.Main.e8193710fd35b608(ptr %.loc54_5, i32 0), !dbg !18
 // CHECK:STDOUT:   ret void, !dbg !19
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -151,121 +151,78 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %C.call, !dbg !49
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CA.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !50 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CB.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !50 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !51
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc20, label %if.else.loc20, !dbg !52
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then.loc20:                                    ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !53
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else.loc20:                                    ; preds = %entry
-// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !54
-// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !54
-// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc23, label %if.else.loc23, !dbg !55
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then.loc23:                                    ; preds = %if.else.loc20
-// CHECK:STDOUT:   %B.call = call ptr @_CB.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !56
-// CHECK:STDOUT:   ret ptr %B.call, !dbg !57
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else.loc23:                                    ; preds = %if.else.loc20
-// CHECK:STDOUT:   %C.call = call ptr @_CC.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !58
-// CHECK:STDOUT:   ret ptr %C.call, !dbg !59
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CB.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !60 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !61
-// CHECK:STDOUT:   %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !62
-// CHECK:STDOUT:   ret i32 %D.call, !dbg !63
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CC.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !64 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !65
-// CHECK:STDOUT:   %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !66
-// CHECK:STDOUT:   ret i32 %D.call, !dbg !67
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CB.Main.66be507887ceee78(double %x, i32 %count) !dbg !68 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !69
-// CHECK:STDOUT:   %D.call = call double @_CD.Main.66be507887ceee78(double %x, i32 %count), !dbg !70
-// CHECK:STDOUT:   ret double %D.call, !dbg !71
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !51
+// CHECK:STDOUT:   %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !52
+// CHECK:STDOUT:   ret i32 %D.call, !dbg !53
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CC.Main.66be507887ceee78(double %x, i32 %count) !dbg !72 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CC.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !54 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !73
-// CHECK:STDOUT:   %D.call = call double @_CD.Main.66be507887ceee78(double %x, i32 %count), !dbg !74
-// CHECK:STDOUT:   ret double %D.call, !dbg !75
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !55
+// CHECK:STDOUT:   %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !56
+// CHECK:STDOUT:   ret i32 %D.call, !dbg !57
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CB.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !76 {
+// CHECK:STDOUT: define linkonce_odr double @_CB.Main.66be507887ceee78(double %x, i32 %count) !dbg !58 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !77
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !78
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !79
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !59
+// CHECK:STDOUT:   %D.call = call double @_CD.Main.66be507887ceee78(double %x, i32 %count), !dbg !60
+// CHECK:STDOUT:   ret double %D.call, !dbg !61
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CC.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !80 {
+// CHECK:STDOUT: define linkonce_odr double @_CC.Main.66be507887ceee78(double %x, i32 %count) !dbg !62 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !81
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !82
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !83
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !63
+// CHECK:STDOUT:   %D.call = call double @_CD.Main.66be507887ceee78(double %x, i32 %count), !dbg !64
+// CHECK:STDOUT:   ret double %D.call, !dbg !65
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CB.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !84 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CB.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !66 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !85
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !86
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !87
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 1), !dbg !67
+// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !68
+// CHECK:STDOUT:   ret ptr %D.call, !dbg !69
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CC.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !88 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CC.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !70 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !89
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !90
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !91
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 2), !dbg !71
+// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !72
+// CHECK:STDOUT:   ret ptr %D.call, !dbg !73
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: declare i32 @printf(ptr, ...)
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !92 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !93
-// CHECK:STDOUT:   %A.call = call i32 @_CA.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !94
-// CHECK:STDOUT:   ret i32 %A.call, !dbg !95
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CD.Main.66be507887ceee78(double %x, i32 %count) !dbg !96 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !74 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !97
-// CHECK:STDOUT:   %A.call = call double @_CA.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !98
-// CHECK:STDOUT:   ret double %A.call, !dbg !99
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !75
+// CHECK:STDOUT:   %A.call = call i32 @_CA.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !76
+// CHECK:STDOUT:   ret i32 %A.call, !dbg !77
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !100 {
+// CHECK:STDOUT: define linkonce_odr double @_CD.Main.66be507887ceee78(double %x, i32 %count) !dbg !78 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !101
-// CHECK:STDOUT:   %A.call = call ptr @_CA.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !102
-// CHECK:STDOUT:   ret ptr %A.call, !dbg !103
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !79
+// CHECK:STDOUT:   %A.call = call double @_CA.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !80
+// CHECK:STDOUT:   ret double %A.call, !dbg !81
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !104 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !82 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !105
-// CHECK:STDOUT:   %A.call = call ptr @_CA.Main.04bf2edaaa84aa22(ptr %x, i32 %int.sadd), !dbg !106
-// CHECK:STDOUT:   ret ptr %A.call, !dbg !107
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !83
+// CHECK:STDOUT:   %A.call = call ptr @_CA.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !84
+// CHECK:STDOUT:   ret ptr %A.call, !dbg !85
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @printf, { 7, 6, 5, 4, 3, 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CA.Main.e8193710fd35b608, { 1, 2, 0 }
+// CHECK:STDOUT: uselistorder ptr @printf, { 5, 4, 3, 2, 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CD.Main.b88d1103f417c6d4, { 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CD.Main.66be507887ceee78, { 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CD.Main.e8193710fd35b608, { 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @_CD.Main.04bf2edaaa84aa22, { 1, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT:
@@ -322,61 +279,39 @@ fn M() {
 // CHECK:STDOUT: !47 = !DILocation(line: 24, column: 5, scope: !40)
 // CHECK:STDOUT: !48 = !DILocation(line: 26, column: 12, scope: !40)
 // CHECK:STDOUT: !49 = !DILocation(line: 26, column: 5, scope: !40)
-// CHECK:STDOUT: !50 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 19, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !51 = !DILocation(line: 20, column: 7, scope: !50)
-// CHECK:STDOUT: !52 = !DILocation(line: 20, column: 6, scope: !50)
-// CHECK:STDOUT: !53 = !DILocation(line: 21, column: 5, scope: !50)
-// CHECK:STDOUT: !54 = !DILocation(line: 23, column: 7, scope: !50)
-// CHECK:STDOUT: !55 = !DILocation(line: 23, column: 6, scope: !50)
-// CHECK:STDOUT: !56 = !DILocation(line: 24, column: 12, scope: !50)
-// CHECK:STDOUT: !57 = !DILocation(line: 24, column: 5, scope: !50)
-// CHECK:STDOUT: !58 = !DILocation(line: 26, column: 12, scope: !50)
-// CHECK:STDOUT: !59 = !DILocation(line: 26, column: 5, scope: !50)
-// CHECK:STDOUT: !60 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.b88d1103f417c6d4", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !61 = !DILocation(line: 32, column: 3, scope: !60)
-// CHECK:STDOUT: !62 = !DILocation(line: 33, column: 10, scope: !60)
-// CHECK:STDOUT: !63 = !DILocation(line: 33, column: 3, scope: !60)
-// CHECK:STDOUT: !64 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.b88d1103f417c6d4", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !65 = !DILocation(line: 37, column: 3, scope: !64)
-// CHECK:STDOUT: !66 = !DILocation(line: 38, column: 10, scope: !64)
-// CHECK:STDOUT: !67 = !DILocation(line: 38, column: 3, scope: !64)
-// CHECK:STDOUT: !68 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.66be507887ceee78", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !69 = !DILocation(line: 32, column: 3, scope: !68)
-// CHECK:STDOUT: !70 = !DILocation(line: 33, column: 10, scope: !68)
-// CHECK:STDOUT: !71 = !DILocation(line: 33, column: 3, scope: !68)
-// CHECK:STDOUT: !72 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.66be507887ceee78", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !73 = !DILocation(line: 37, column: 3, scope: !72)
-// CHECK:STDOUT: !74 = !DILocation(line: 38, column: 10, scope: !72)
-// CHECK:STDOUT: !75 = !DILocation(line: 38, column: 3, scope: !72)
-// CHECK:STDOUT: !76 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.e8193710fd35b608", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !77 = !DILocation(line: 32, column: 3, scope: !76)
-// CHECK:STDOUT: !78 = !DILocation(line: 33, column: 10, scope: !76)
-// CHECK:STDOUT: !79 = !DILocation(line: 33, column: 3, scope: !76)
-// CHECK:STDOUT: !80 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.e8193710fd35b608", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !81 = !DILocation(line: 37, column: 3, scope: !80)
-// CHECK:STDOUT: !82 = !DILocation(line: 38, column: 10, scope: !80)
-// CHECK:STDOUT: !83 = !DILocation(line: 38, column: 3, scope: !80)
-// CHECK:STDOUT: !84 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !85 = !DILocation(line: 32, column: 3, scope: !84)
-// CHECK:STDOUT: !86 = !DILocation(line: 33, column: 10, scope: !84)
-// CHECK:STDOUT: !87 = !DILocation(line: 33, column: 3, scope: !84)
-// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !89 = !DILocation(line: 37, column: 3, scope: !88)
-// CHECK:STDOUT: !90 = !DILocation(line: 38, column: 10, scope: !88)
-// CHECK:STDOUT: !91 = !DILocation(line: 38, column: 3, scope: !88)
-// CHECK:STDOUT: !92 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.b88d1103f417c6d4", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !93 = !DILocation(line: 42, column: 15, scope: !92)
-// CHECK:STDOUT: !94 = !DILocation(line: 42, column: 10, scope: !92)
-// CHECK:STDOUT: !95 = !DILocation(line: 42, column: 3, scope: !92)
-// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.66be507887ceee78", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !97 = !DILocation(line: 42, column: 15, scope: !96)
-// CHECK:STDOUT: !98 = !DILocation(line: 42, column: 10, scope: !96)
-// CHECK:STDOUT: !99 = !DILocation(line: 42, column: 3, scope: !96)
-// CHECK:STDOUT: !100 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.e8193710fd35b608", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !101 = !DILocation(line: 42, column: 15, scope: !100)
-// CHECK:STDOUT: !102 = !DILocation(line: 42, column: 10, scope: !100)
-// CHECK:STDOUT: !103 = !DILocation(line: 42, column: 3, scope: !100)
-// CHECK:STDOUT: !104 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !105 = !DILocation(line: 42, column: 15, scope: !104)
-// CHECK:STDOUT: !106 = !DILocation(line: 42, column: 10, scope: !104)
-// CHECK:STDOUT: !107 = !DILocation(line: 42, column: 3, scope: !104)
+// CHECK:STDOUT: !50 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.b88d1103f417c6d4", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !51 = !DILocation(line: 32, column: 3, scope: !50)
+// CHECK:STDOUT: !52 = !DILocation(line: 33, column: 10, scope: !50)
+// CHECK:STDOUT: !53 = !DILocation(line: 33, column: 3, scope: !50)
+// CHECK:STDOUT: !54 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.b88d1103f417c6d4", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !55 = !DILocation(line: 37, column: 3, scope: !54)
+// CHECK:STDOUT: !56 = !DILocation(line: 38, column: 10, scope: !54)
+// CHECK:STDOUT: !57 = !DILocation(line: 38, column: 3, scope: !54)
+// CHECK:STDOUT: !58 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.66be507887ceee78", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !59 = !DILocation(line: 32, column: 3, scope: !58)
+// CHECK:STDOUT: !60 = !DILocation(line: 33, column: 10, scope: !58)
+// CHECK:STDOUT: !61 = !DILocation(line: 33, column: 3, scope: !58)
+// CHECK:STDOUT: !62 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.66be507887ceee78", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !63 = !DILocation(line: 37, column: 3, scope: !62)
+// CHECK:STDOUT: !64 = !DILocation(line: 38, column: 10, scope: !62)
+// CHECK:STDOUT: !65 = !DILocation(line: 38, column: 3, scope: !62)
+// CHECK:STDOUT: !66 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.e8193710fd35b608", scope: null, file: !3, line: 31, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !67 = !DILocation(line: 32, column: 3, scope: !66)
+// CHECK:STDOUT: !68 = !DILocation(line: 33, column: 10, scope: !66)
+// CHECK:STDOUT: !69 = !DILocation(line: 33, column: 3, scope: !66)
+// CHECK:STDOUT: !70 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.e8193710fd35b608", scope: null, file: !3, line: 36, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !71 = !DILocation(line: 37, column: 3, scope: !70)
+// CHECK:STDOUT: !72 = !DILocation(line: 38, column: 10, scope: !70)
+// CHECK:STDOUT: !73 = !DILocation(line: 38, column: 3, scope: !70)
+// CHECK:STDOUT: !74 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.b88d1103f417c6d4", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !75 = !DILocation(line: 42, column: 15, scope: !74)
+// CHECK:STDOUT: !76 = !DILocation(line: 42, column: 10, scope: !74)
+// CHECK:STDOUT: !77 = !DILocation(line: 42, column: 3, scope: !74)
+// CHECK:STDOUT: !78 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.66be507887ceee78", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !79 = !DILocation(line: 42, column: 15, scope: !78)
+// CHECK:STDOUT: !80 = !DILocation(line: 42, column: 10, scope: !78)
+// CHECK:STDOUT: !81 = !DILocation(line: 42, column: 3, scope: !78)
+// CHECK:STDOUT: !82 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.e8193710fd35b608", scope: null, file: !3, line: 41, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !83 = !DILocation(line: 42, column: 15, scope: !82)
+// CHECK:STDOUT: !84 = !DILocation(line: 42, column: 10, scope: !82)
+// CHECK:STDOUT: !85 = !DILocation(line: 42, column: 3, scope: !82)

+ 27 - 68
toolchain/lower/testdata/function/generic/call_recursive_mutual.carbon

@@ -21,7 +21,7 @@ fn F[T:! type](x: T, count: i32) -> T {
 }
 
 fn G[T:! type](x: T, count: i32) -> T {
-  if (count > 3) {
+  if (count > 4) {
     return x;
   }
   return F(x, count + 1);
@@ -61,7 +61,7 @@ fn M() {
 // CHECK:STDOUT:   %.loc38_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15
 // CHECK:STDOUT:   %F.call.loc38 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc38_5, i32 0), !dbg !16
 // CHECK:STDOUT:   %.loc39_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17
-// CHECK:STDOUT:   %F.call.loc39 = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %.loc39_5, i32 0), !dbg !18
+// CHECK:STDOUT:   %F.call.loc39 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc39_5, i32 0), !dbg !18
 // CHECK:STDOUT:   ret void, !dbg !19
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -110,78 +110,51 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %G.call, !dbg !40
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !41 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !41 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 3, !dbg !42
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !42
 // CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !43
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !44
+// CHECK:STDOUT:   ret i32 %x, !dbg !44
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else:                                          ; preds = %entry
 // CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !45
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.04bf2edaaa84aa22(ptr %x, i32 %int.sadd), !dbg !46
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !47
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !46
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !47
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !48 {
+// CHECK:STDOUT: define linkonce_odr double @_CG.Main.66be507887ceee78(double %x, i32 %count) !dbg !48 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 3, !dbg !49
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !49
 // CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !50
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   ret i32 %x, !dbg !51
+// CHECK:STDOUT:   ret double %x, !dbg !51
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else:                                          ; preds = %entry
 // CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !52
-// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !53
-// CHECK:STDOUT:   ret i32 %F.call, !dbg !54
+// CHECK:STDOUT:   %F.call = call double @_CF.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !53
+// CHECK:STDOUT:   ret double %F.call, !dbg !54
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CG.Main.66be507887ceee78(double %x, i32 %count) !dbg !55 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !55 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 3, !dbg !56
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !56
 // CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !57
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   ret double %x, !dbg !58
+// CHECK:STDOUT:   ret ptr %x, !dbg !58
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else:                                          ; preds = %entry
 // CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !59
-// CHECK:STDOUT:   %F.call = call double @_CF.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !60
-// CHECK:STDOUT:   ret double %F.call, !dbg !61
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !62 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 3, !dbg !63
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !64
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !65
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else:                                          ; preds = %entry
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !66
-// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !67
-// CHECK:STDOUT:   ret ptr %F.call, !dbg !68
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !69 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 3, !dbg !70
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !71
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !72
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else:                                          ; preds = %entry
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !73
-// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %x, i32 %int.sadd), !dbg !74
-// CHECK:STDOUT:   ret ptr %F.call, !dbg !75
+// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !60
+// CHECK:STDOUT:   ret ptr %F.call, !dbg !61
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.e8193710fd35b608, { 1, 2, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT:
@@ -229,38 +202,24 @@ fn M() {
 // CHECK:STDOUT: !38 = !DILocation(line: 20, column: 15, scope: !34)
 // CHECK:STDOUT: !39 = !DILocation(line: 20, column: 10, scope: !34)
 // CHECK:STDOUT: !40 = !DILocation(line: 20, column: 3, scope: !34)
-// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !42 = !DILocation(line: 17, column: 7, scope: !41)
-// CHECK:STDOUT: !43 = !DILocation(line: 17, column: 6, scope: !41)
-// CHECK:STDOUT: !44 = !DILocation(line: 18, column: 5, scope: !41)
-// CHECK:STDOUT: !45 = !DILocation(line: 20, column: 15, scope: !41)
-// CHECK:STDOUT: !46 = !DILocation(line: 20, column: 10, scope: !41)
-// CHECK:STDOUT: !47 = !DILocation(line: 20, column: 3, scope: !41)
-// CHECK:STDOUT: !48 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !42 = !DILocation(line: 24, column: 7, scope: !41)
+// CHECK:STDOUT: !43 = !DILocation(line: 24, column: 6, scope: !41)
+// CHECK:STDOUT: !44 = !DILocation(line: 25, column: 5, scope: !41)
+// CHECK:STDOUT: !45 = !DILocation(line: 27, column: 15, scope: !41)
+// CHECK:STDOUT: !46 = !DILocation(line: 27, column: 10, scope: !41)
+// CHECK:STDOUT: !47 = !DILocation(line: 27, column: 3, scope: !41)
+// CHECK:STDOUT: !48 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !49 = !DILocation(line: 24, column: 7, scope: !48)
 // CHECK:STDOUT: !50 = !DILocation(line: 24, column: 6, scope: !48)
 // CHECK:STDOUT: !51 = !DILocation(line: 25, column: 5, scope: !48)
 // CHECK:STDOUT: !52 = !DILocation(line: 27, column: 15, scope: !48)
 // CHECK:STDOUT: !53 = !DILocation(line: 27, column: 10, scope: !48)
 // CHECK:STDOUT: !54 = !DILocation(line: 27, column: 3, scope: !48)
-// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e8193710fd35b608", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !56 = !DILocation(line: 24, column: 7, scope: !55)
 // CHECK:STDOUT: !57 = !DILocation(line: 24, column: 6, scope: !55)
 // CHECK:STDOUT: !58 = !DILocation(line: 25, column: 5, scope: !55)
 // CHECK:STDOUT: !59 = !DILocation(line: 27, column: 15, scope: !55)
 // CHECK:STDOUT: !60 = !DILocation(line: 27, column: 10, scope: !55)
 // CHECK:STDOUT: !61 = !DILocation(line: 27, column: 3, scope: !55)
-// CHECK:STDOUT: !62 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e8193710fd35b608", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !63 = !DILocation(line: 24, column: 7, scope: !62)
-// CHECK:STDOUT: !64 = !DILocation(line: 24, column: 6, scope: !62)
-// CHECK:STDOUT: !65 = !DILocation(line: 25, column: 5, scope: !62)
-// CHECK:STDOUT: !66 = !DILocation(line: 27, column: 15, scope: !62)
-// CHECK:STDOUT: !67 = !DILocation(line: 27, column: 10, scope: !62)
-// CHECK:STDOUT: !68 = !DILocation(line: 27, column: 3, scope: !62)
-// CHECK:STDOUT: !69 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 23, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !70 = !DILocation(line: 24, column: 7, scope: !69)
-// CHECK:STDOUT: !71 = !DILocation(line: 24, column: 6, scope: !69)
-// CHECK:STDOUT: !72 = !DILocation(line: 25, column: 5, scope: !69)
-// CHECK:STDOUT: !73 = !DILocation(line: 27, column: 15, scope: !69)
-// CHECK:STDOUT: !74 = !DILocation(line: 27, column: 10, scope: !69)
-// CHECK:STDOUT: !75 = !DILocation(line: 27, column: 3, scope: !69)

+ 98 - 0
toolchain/lower/testdata/function/generic/call_recursive_reorder.carbon

@@ -0,0 +1,98 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/generic/call_recursive_reorder.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_recursive_reorder.carbon
+
+// Builds on `call_recursive_basic.carbon`.
+
+fn F[T:! type, U:! type](x: T, y: U, count: i32) -> i32 {
+  if (count > 2) {
+    return count;
+  }
+  return F(y, x, count + 1);
+}
+
+fn M() {
+  var ptr_i32 : i32*;
+  var ptr_f64 : f64*;
+  var ptr_bool : bool*;
+
+  F(ptr_i32, ptr_bool, 0);
+  F(ptr_f64, ptr_bool, 0);
+}
+
+// CHECK:STDOUT: ; ModuleID = 'call_recursive_reorder.carbon'
+// CHECK:STDOUT: source_filename = "call_recursive_reorder.carbon"
+// CHECK:STDOUT:
+// CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %ptr_i32.var = alloca ptr, align 8, !dbg !7
+// CHECK:STDOUT:   %ptr_f64.var = alloca ptr, align 8, !dbg !8
+// CHECK:STDOUT:   %ptr_bool.var = alloca ptr, align 8, !dbg !9
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i32.var), !dbg !7
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !8
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_bool.var), !dbg !9
+// CHECK:STDOUT:   %.loc25_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !10
+// CHECK:STDOUT:   %.loc25_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !11
+// CHECK:STDOUT:   %F.call.loc25 = call i32 @_CF.Main.2fe87eb83f5a4614(ptr %.loc25_5, ptr %.loc25_14, i32 0), !dbg !12
+// CHECK:STDOUT:   %.loc26_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !13
+// CHECK:STDOUT:   %.loc26_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !14
+// CHECK:STDOUT:   %F.call.loc26 = call i32 @_CF.Main.2fe87eb83f5a4614(ptr %.loc26_5, ptr %.loc26_14, i32 0), !dbg !15
+// CHECK:STDOUT:   ret void, !dbg !16
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
+// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.2fe87eb83f5a4614(ptr %x, ptr %y, i32 %count) !dbg !17 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !18
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !19
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !20
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !21
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.2fe87eb83f5a4614(ptr %y, ptr %x, i32 %int.sadd), !dbg !22
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !23
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; uselistorder directives
+// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.2fe87eb83f5a4614, { 0, 2, 1 }
+// CHECK:STDOUT:
+// CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
+// CHECK:STDOUT:
+// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
+// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
+// CHECK:STDOUT:
+// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
+// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
+// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+// CHECK:STDOUT: !3 = !DIFile(filename: "call_recursive_reorder.carbon", directory: "")
+// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
+// CHECK:STDOUT: !6 = !{}
+// CHECK:STDOUT: !7 = !DILocation(line: 21, column: 3, scope: !4)
+// CHECK:STDOUT: !8 = !DILocation(line: 22, column: 3, scope: !4)
+// CHECK:STDOUT: !9 = !DILocation(line: 23, column: 3, scope: !4)
+// CHECK:STDOUT: !10 = !DILocation(line: 25, column: 5, scope: !4)
+// CHECK:STDOUT: !11 = !DILocation(line: 25, column: 14, scope: !4)
+// CHECK:STDOUT: !12 = !DILocation(line: 25, column: 3, scope: !4)
+// CHECK:STDOUT: !13 = !DILocation(line: 26, column: 5, scope: !4)
+// CHECK:STDOUT: !14 = !DILocation(line: 26, column: 14, scope: !4)
+// CHECK:STDOUT: !15 = !DILocation(line: 26, column: 3, scope: !4)
+// CHECK:STDOUT: !16 = !DILocation(line: 20, column: 1, scope: !4)
+// CHECK:STDOUT: !17 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.2fe87eb83f5a4614", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !18 = !DILocation(line: 14, column: 7, scope: !17)
+// CHECK:STDOUT: !19 = !DILocation(line: 14, column: 6, scope: !17)
+// CHECK:STDOUT: !20 = !DILocation(line: 15, column: 5, scope: !17)
+// CHECK:STDOUT: !21 = !DILocation(line: 17, column: 18, scope: !17)
+// CHECK:STDOUT: !22 = !DILocation(line: 17, column: 10, scope: !17)
+// CHECK:STDOUT: !23 = !DILocation(line: 17, column: 3, scope: !17)

+ 350 - 0
toolchain/lower/testdata/function/generic/call_recursive_reorder_more.carbon

@@ -0,0 +1,350 @@
+// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// AUTOUPDATE
+// TIP: To test this file alone, run:
+// TIP:   bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/function/generic/call_recursive_reorder_more.carbon
+// TIP: To dump output, run:
+// TIP:   bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/function/generic/call_recursive_reorder_more.carbon
+
+// Builds on `call_recursive_reorder.carbon`.
+
+fn F[T:! type, U:! type, V:! type](x: T, y: U, z: V, count: i32) -> i32 {
+  if (count > 2) {
+    return count;
+  }
+  return F(x, z, y, count + 1);
+}
+
+fn M() {
+  var val_i16 : i16;
+  var val_i32 : i32;
+  var val_i64 : i64;
+  var val_f64 : f64;
+  var val_bool : bool;
+
+  var ptr_i16 : i16*;
+  var ptr_i32 : i32*;
+  var ptr_i64 : i64*;
+  var ptr_bool : bool*;
+
+  // Insert noise: non equivalent with the second set of calls.
+  // (4*2 + 1 functions generated; first 3 coalesce with each other - self
+  // recursion - , 4th remains as 2 specifics, 5th is already self recursion.
+  // Start: 9 functions. End: 6 functions.
+  F(val_i16, ptr_i32, ptr_bool, 0);
+  F(val_i32, ptr_bool, ptr_i64, 0);
+  F(val_bool, ptr_bool, ptr_i16, 0);
+  F(val_i64, val_bool, ptr_bool, 0);
+  F(val_f64, ptr_bool, ptr_bool, 0);
+
+  // All equivalent (6*2 + 1 generated initially, coalesced to one)
+  // Start: 13 functions. End: 1 function.
+  F(ptr_bool, ptr_i16, ptr_i32, 0);
+  F(ptr_bool, ptr_i16, ptr_i64, 0);
+  F(ptr_i32, ptr_bool, ptr_i16, 0);
+  F(ptr_i32, ptr_bool, ptr_i64, 0);
+  F(ptr_i16, ptr_i32, ptr_i64, 0);
+  F(ptr_i64, ptr_bool, ptr_i16, 0);
+  F(ptr_bool, ptr_bool, ptr_bool, 0);
+}
+
+// CHECK:STDOUT: ; ModuleID = 'call_recursive_reorder_more.carbon'
+// CHECK:STDOUT: source_filename = "call_recursive_reorder_more.carbon"
+// CHECK:STDOUT:
+// CHECK:STDOUT: define void @_CM.Main() !dbg !4 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %val_i16.var = alloca i16, align 2, !dbg !7
+// CHECK:STDOUT:   %val_i32.var = alloca i32, align 4, !dbg !8
+// CHECK:STDOUT:   %val_i64.var = alloca i64, align 8, !dbg !9
+// CHECK:STDOUT:   %val_f64.var = alloca double, align 8, !dbg !10
+// CHECK:STDOUT:   %val_bool.var = alloca i1, align 1, !dbg !11
+// CHECK:STDOUT:   %ptr_i16.var = alloca ptr, align 8, !dbg !12
+// CHECK:STDOUT:   %ptr_i32.var = alloca ptr, align 8, !dbg !13
+// CHECK:STDOUT:   %ptr_i64.var = alloca ptr, align 8, !dbg !14
+// CHECK:STDOUT:   %ptr_bool.var = alloca ptr, align 8, !dbg !15
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 2, ptr %val_i16.var), !dbg !7
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 4, ptr %val_i32.var), !dbg !8
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %val_i64.var), !dbg !9
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %val_f64.var), !dbg !10
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 1, ptr %val_bool.var), !dbg !11
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i16.var), !dbg !12
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i32.var), !dbg !13
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i64.var), !dbg !14
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_bool.var), !dbg !15
+// CHECK:STDOUT:   %.loc36_5 = load i16, ptr %val_i16.var, align 2, !dbg !16
+// CHECK:STDOUT:   %.loc36_14 = load ptr, ptr %ptr_i32.var, align 8, !dbg !17
+// CHECK:STDOUT:   %.loc36_23 = load ptr, ptr %ptr_bool.var, align 8, !dbg !18
+// CHECK:STDOUT:   %F.call.loc36 = call i32 @_CF.Main.077d2bb2ab5eee86(i16 %.loc36_5, ptr %.loc36_14, ptr %.loc36_23, i32 0), !dbg !19
+// CHECK:STDOUT:   %.loc37_5 = load i32, ptr %val_i32.var, align 4, !dbg !20
+// CHECK:STDOUT:   %.loc37_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !21
+// CHECK:STDOUT:   %.loc37_24 = load ptr, ptr %ptr_i64.var, align 8, !dbg !22
+// CHECK:STDOUT:   %F.call.loc37 = call i32 @_CF.Main.9a89ac9e10448feb(i32 %.loc37_5, ptr %.loc37_14, ptr %.loc37_24, i32 0), !dbg !23
+// CHECK:STDOUT:   %.loc38_5 = load i1, ptr %val_bool.var, align 1, !dbg !24
+// CHECK:STDOUT:   %.loc38_15 = load ptr, ptr %ptr_bool.var, align 8, !dbg !25
+// CHECK:STDOUT:   %.loc38_25 = load ptr, ptr %ptr_i16.var, align 8, !dbg !26
+// CHECK:STDOUT:   %F.call.loc38 = call i32 @_CF.Main.76a945443862cc1f(i1 %.loc38_5, ptr %.loc38_15, ptr %.loc38_25, i32 0), !dbg !27
+// CHECK:STDOUT:   %.loc39_5 = load i64, ptr %val_i64.var, align 4, !dbg !28
+// CHECK:STDOUT:   %.loc39_14 = load i1, ptr %val_bool.var, align 1, !dbg !29
+// CHECK:STDOUT:   %.loc39_24 = load ptr, ptr %ptr_bool.var, align 8, !dbg !30
+// CHECK:STDOUT:   %F.call.loc39 = call i32 @_CF.Main.02da1a7614ea56b6(i64 %.loc39_5, i1 %.loc39_14, ptr %.loc39_24, i32 0), !dbg !31
+// CHECK:STDOUT:   %.loc40_5 = load double, ptr %val_f64.var, align 8, !dbg !32
+// CHECK:STDOUT:   %.loc40_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !33
+// CHECK:STDOUT:   %.loc40_24 = load ptr, ptr %ptr_bool.var, align 8, !dbg !34
+// CHECK:STDOUT:   %F.call.loc40 = call i32 @_CF.Main.f51a89281f4fb62e(double %.loc40_5, ptr %.loc40_14, ptr %.loc40_24, i32 0), !dbg !35
+// CHECK:STDOUT:   %.loc44_5 = load ptr, ptr %ptr_bool.var, align 8, !dbg !36
+// CHECK:STDOUT:   %.loc44_15 = load ptr, ptr %ptr_i16.var, align 8, !dbg !37
+// CHECK:STDOUT:   %.loc44_24 = load ptr, ptr %ptr_i32.var, align 8, !dbg !38
+// CHECK:STDOUT:   %F.call.loc44 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc44_5, ptr %.loc44_15, ptr %.loc44_24, i32 0), !dbg !39
+// CHECK:STDOUT:   %.loc45_5 = load ptr, ptr %ptr_bool.var, align 8, !dbg !40
+// CHECK:STDOUT:   %.loc45_15 = load ptr, ptr %ptr_i16.var, align 8, !dbg !41
+// CHECK:STDOUT:   %.loc45_24 = load ptr, ptr %ptr_i64.var, align 8, !dbg !42
+// CHECK:STDOUT:   %F.call.loc45 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc45_5, ptr %.loc45_15, ptr %.loc45_24, i32 0), !dbg !43
+// CHECK:STDOUT:   %.loc46_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !44
+// CHECK:STDOUT:   %.loc46_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !45
+// CHECK:STDOUT:   %.loc46_24 = load ptr, ptr %ptr_i16.var, align 8, !dbg !46
+// CHECK:STDOUT:   %F.call.loc46 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc46_5, ptr %.loc46_14, ptr %.loc46_24, i32 0), !dbg !47
+// CHECK:STDOUT:   %.loc47_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !48
+// CHECK:STDOUT:   %.loc47_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !49
+// CHECK:STDOUT:   %.loc47_24 = load ptr, ptr %ptr_i64.var, align 8, !dbg !50
+// CHECK:STDOUT:   %F.call.loc47 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc47_5, ptr %.loc47_14, ptr %.loc47_24, i32 0), !dbg !51
+// CHECK:STDOUT:   %.loc48_5 = load ptr, ptr %ptr_i16.var, align 8, !dbg !52
+// CHECK:STDOUT:   %.loc48_14 = load ptr, ptr %ptr_i32.var, align 8, !dbg !53
+// CHECK:STDOUT:   %.loc48_23 = load ptr, ptr %ptr_i64.var, align 8, !dbg !54
+// CHECK:STDOUT:   %F.call.loc48 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc48_5, ptr %.loc48_14, ptr %.loc48_23, i32 0), !dbg !55
+// CHECK:STDOUT:   %.loc49_5 = load ptr, ptr %ptr_i64.var, align 8, !dbg !56
+// CHECK:STDOUT:   %.loc49_14 = load ptr, ptr %ptr_bool.var, align 8, !dbg !57
+// CHECK:STDOUT:   %.loc49_24 = load ptr, ptr %ptr_i16.var, align 8, !dbg !58
+// CHECK:STDOUT:   %F.call.loc49 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc49_5, ptr %.loc49_14, ptr %.loc49_24, i32 0), !dbg !59
+// CHECK:STDOUT:   %.loc50_5 = load ptr, ptr %ptr_bool.var, align 8, !dbg !60
+// CHECK:STDOUT:   %.loc50_15 = load ptr, ptr %ptr_bool.var, align 8, !dbg !61
+// CHECK:STDOUT:   %.loc50_25 = load ptr, ptr %ptr_bool.var, align 8, !dbg !62
+// CHECK:STDOUT:   %F.call.loc50 = call i32 @_CF.Main.7776e910959584d9(ptr %.loc50_5, ptr %.loc50_15, ptr %.loc50_25, i32 0), !dbg !63
+// CHECK:STDOUT:   ret void, !dbg !64
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
+// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.077d2bb2ab5eee86(i16 %x, ptr %y, ptr %z, i32 %count) !dbg !65 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !66
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !67
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !68
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !69
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.077d2bb2ab5eee86(i16 %x, ptr %z, ptr %y, i32 %int.sadd), !dbg !70
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !71
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.9a89ac9e10448feb(i32 %x, ptr %y, ptr %z, i32 %count) !dbg !72 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !73
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !74
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !75
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !76
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.9a89ac9e10448feb(i32 %x, ptr %z, ptr %y, i32 %int.sadd), !dbg !77
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !78
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.76a945443862cc1f(i1 %x, ptr %y, ptr %z, i32 %count) !dbg !79 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !80
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !81
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !82
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !83
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.76a945443862cc1f(i1 %x, ptr %z, ptr %y, i32 %int.sadd), !dbg !84
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !85
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.02da1a7614ea56b6(i64 %x, i1 %y, ptr %z, i32 %count) !dbg !86 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !87
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !88
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !89
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !90
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.bea8bae6e14e4034(i64 %x, ptr %z, i1 %y, i32 %int.sadd), !dbg !91
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !92
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.f51a89281f4fb62e(double %x, ptr %y, ptr %z, i32 %count) !dbg !93 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !94
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !95
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !96
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !97
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.f51a89281f4fb62e(double %x, ptr %z, ptr %y, i32 %int.sadd), !dbg !98
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !99
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.7776e910959584d9(ptr %x, ptr %y, ptr %z, i32 %count) !dbg !100 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !101
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !102
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !103
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !104
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.7776e910959584d9(ptr %x, ptr %z, ptr %y, i32 %int.sadd), !dbg !105
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !106
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.bea8bae6e14e4034(i64 %x, ptr %y, i1 %z, i32 %count) !dbg !107 {
+// CHECK:STDOUT: entry:
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 2, !dbg !108
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then, label %if.else, !dbg !109
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.then:                                          ; preds = %entry
+// CHECK:STDOUT:   ret i32 %count, !dbg !110
+// CHECK:STDOUT:
+// CHECK:STDOUT: if.else:                                          ; preds = %entry
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !111
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.02da1a7614ea56b6(i64 %x, i1 %z, ptr %y, i32 %int.sadd), !dbg !112
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !113
+// CHECK:STDOUT: }
+// CHECK:STDOUT:
+// CHECK:STDOUT: ; uselistorder directives
+// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 8, 7, 6, 5, 4, 3, 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.7776e910959584d9, { 5, 7, 6, 4, 3, 2, 1, 0 }
+// CHECK:STDOUT:
+// CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
+// CHECK:STDOUT:
+// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
+// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
+// CHECK:STDOUT:
+// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
+// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
+// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+// CHECK:STDOUT: !3 = !DIFile(filename: "call_recursive_reorder_more.carbon", directory: "")
+// CHECK:STDOUT: !4 = distinct !DISubprogram(name: "M", linkageName: "_CM.Main", scope: null, file: !3, line: 20, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !5 = !DISubroutineType(types: !6)
+// CHECK:STDOUT: !6 = !{}
+// CHECK:STDOUT: !7 = !DILocation(line: 21, column: 3, scope: !4)
+// CHECK:STDOUT: !8 = !DILocation(line: 22, column: 3, scope: !4)
+// CHECK:STDOUT: !9 = !DILocation(line: 23, column: 3, scope: !4)
+// CHECK:STDOUT: !10 = !DILocation(line: 24, column: 3, scope: !4)
+// CHECK:STDOUT: !11 = !DILocation(line: 25, column: 3, scope: !4)
+// CHECK:STDOUT: !12 = !DILocation(line: 27, column: 3, scope: !4)
+// CHECK:STDOUT: !13 = !DILocation(line: 28, column: 3, scope: !4)
+// CHECK:STDOUT: !14 = !DILocation(line: 29, column: 3, scope: !4)
+// CHECK:STDOUT: !15 = !DILocation(line: 30, column: 3, scope: !4)
+// CHECK:STDOUT: !16 = !DILocation(line: 36, column: 5, scope: !4)
+// CHECK:STDOUT: !17 = !DILocation(line: 36, column: 14, scope: !4)
+// CHECK:STDOUT: !18 = !DILocation(line: 36, column: 23, scope: !4)
+// CHECK:STDOUT: !19 = !DILocation(line: 36, column: 3, scope: !4)
+// CHECK:STDOUT: !20 = !DILocation(line: 37, column: 5, scope: !4)
+// CHECK:STDOUT: !21 = !DILocation(line: 37, column: 14, scope: !4)
+// CHECK:STDOUT: !22 = !DILocation(line: 37, column: 24, scope: !4)
+// CHECK:STDOUT: !23 = !DILocation(line: 37, column: 3, scope: !4)
+// CHECK:STDOUT: !24 = !DILocation(line: 38, column: 5, scope: !4)
+// CHECK:STDOUT: !25 = !DILocation(line: 38, column: 15, scope: !4)
+// CHECK:STDOUT: !26 = !DILocation(line: 38, column: 25, scope: !4)
+// CHECK:STDOUT: !27 = !DILocation(line: 38, column: 3, scope: !4)
+// CHECK:STDOUT: !28 = !DILocation(line: 39, column: 5, scope: !4)
+// CHECK:STDOUT: !29 = !DILocation(line: 39, column: 14, scope: !4)
+// CHECK:STDOUT: !30 = !DILocation(line: 39, column: 24, scope: !4)
+// CHECK:STDOUT: !31 = !DILocation(line: 39, column: 3, scope: !4)
+// CHECK:STDOUT: !32 = !DILocation(line: 40, column: 5, scope: !4)
+// CHECK:STDOUT: !33 = !DILocation(line: 40, column: 14, scope: !4)
+// CHECK:STDOUT: !34 = !DILocation(line: 40, column: 24, scope: !4)
+// CHECK:STDOUT: !35 = !DILocation(line: 40, column: 3, scope: !4)
+// CHECK:STDOUT: !36 = !DILocation(line: 44, column: 5, scope: !4)
+// CHECK:STDOUT: !37 = !DILocation(line: 44, column: 15, scope: !4)
+// CHECK:STDOUT: !38 = !DILocation(line: 44, column: 24, scope: !4)
+// CHECK:STDOUT: !39 = !DILocation(line: 44, column: 3, scope: !4)
+// CHECK:STDOUT: !40 = !DILocation(line: 45, column: 5, scope: !4)
+// CHECK:STDOUT: !41 = !DILocation(line: 45, column: 15, scope: !4)
+// CHECK:STDOUT: !42 = !DILocation(line: 45, column: 24, scope: !4)
+// CHECK:STDOUT: !43 = !DILocation(line: 45, column: 3, scope: !4)
+// CHECK:STDOUT: !44 = !DILocation(line: 46, column: 5, scope: !4)
+// CHECK:STDOUT: !45 = !DILocation(line: 46, column: 14, scope: !4)
+// CHECK:STDOUT: !46 = !DILocation(line: 46, column: 24, scope: !4)
+// CHECK:STDOUT: !47 = !DILocation(line: 46, column: 3, scope: !4)
+// CHECK:STDOUT: !48 = !DILocation(line: 47, column: 5, scope: !4)
+// CHECK:STDOUT: !49 = !DILocation(line: 47, column: 14, scope: !4)
+// CHECK:STDOUT: !50 = !DILocation(line: 47, column: 24, scope: !4)
+// CHECK:STDOUT: !51 = !DILocation(line: 47, column: 3, scope: !4)
+// CHECK:STDOUT: !52 = !DILocation(line: 48, column: 5, scope: !4)
+// CHECK:STDOUT: !53 = !DILocation(line: 48, column: 14, scope: !4)
+// CHECK:STDOUT: !54 = !DILocation(line: 48, column: 23, scope: !4)
+// CHECK:STDOUT: !55 = !DILocation(line: 48, column: 3, scope: !4)
+// CHECK:STDOUT: !56 = !DILocation(line: 49, column: 5, scope: !4)
+// CHECK:STDOUT: !57 = !DILocation(line: 49, column: 14, scope: !4)
+// CHECK:STDOUT: !58 = !DILocation(line: 49, column: 24, scope: !4)
+// CHECK:STDOUT: !59 = !DILocation(line: 49, column: 3, scope: !4)
+// CHECK:STDOUT: !60 = !DILocation(line: 50, column: 5, scope: !4)
+// CHECK:STDOUT: !61 = !DILocation(line: 50, column: 15, scope: !4)
+// CHECK:STDOUT: !62 = !DILocation(line: 50, column: 25, scope: !4)
+// CHECK:STDOUT: !63 = !DILocation(line: 50, column: 3, scope: !4)
+// CHECK:STDOUT: !64 = !DILocation(line: 20, column: 1, scope: !4)
+// CHECK:STDOUT: !65 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.077d2bb2ab5eee86", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !66 = !DILocation(line: 14, column: 7, scope: !65)
+// CHECK:STDOUT: !67 = !DILocation(line: 14, column: 6, scope: !65)
+// CHECK:STDOUT: !68 = !DILocation(line: 15, column: 5, scope: !65)
+// CHECK:STDOUT: !69 = !DILocation(line: 17, column: 21, scope: !65)
+// CHECK:STDOUT: !70 = !DILocation(line: 17, column: 10, scope: !65)
+// CHECK:STDOUT: !71 = !DILocation(line: 17, column: 3, scope: !65)
+// CHECK:STDOUT: !72 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.9a89ac9e10448feb", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !73 = !DILocation(line: 14, column: 7, scope: !72)
+// CHECK:STDOUT: !74 = !DILocation(line: 14, column: 6, scope: !72)
+// CHECK:STDOUT: !75 = !DILocation(line: 15, column: 5, scope: !72)
+// CHECK:STDOUT: !76 = !DILocation(line: 17, column: 21, scope: !72)
+// CHECK:STDOUT: !77 = !DILocation(line: 17, column: 10, scope: !72)
+// CHECK:STDOUT: !78 = !DILocation(line: 17, column: 3, scope: !72)
+// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.76a945443862cc1f", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !80 = !DILocation(line: 14, column: 7, scope: !79)
+// CHECK:STDOUT: !81 = !DILocation(line: 14, column: 6, scope: !79)
+// CHECK:STDOUT: !82 = !DILocation(line: 15, column: 5, scope: !79)
+// CHECK:STDOUT: !83 = !DILocation(line: 17, column: 21, scope: !79)
+// CHECK:STDOUT: !84 = !DILocation(line: 17, column: 10, scope: !79)
+// CHECK:STDOUT: !85 = !DILocation(line: 17, column: 3, scope: !79)
+// CHECK:STDOUT: !86 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.02da1a7614ea56b6", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !87 = !DILocation(line: 14, column: 7, scope: !86)
+// CHECK:STDOUT: !88 = !DILocation(line: 14, column: 6, scope: !86)
+// CHECK:STDOUT: !89 = !DILocation(line: 15, column: 5, scope: !86)
+// CHECK:STDOUT: !90 = !DILocation(line: 17, column: 21, scope: !86)
+// CHECK:STDOUT: !91 = !DILocation(line: 17, column: 10, scope: !86)
+// CHECK:STDOUT: !92 = !DILocation(line: 17, column: 3, scope: !86)
+// CHECK:STDOUT: !93 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.f51a89281f4fb62e", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !94 = !DILocation(line: 14, column: 7, scope: !93)
+// CHECK:STDOUT: !95 = !DILocation(line: 14, column: 6, scope: !93)
+// CHECK:STDOUT: !96 = !DILocation(line: 15, column: 5, scope: !93)
+// CHECK:STDOUT: !97 = !DILocation(line: 17, column: 21, scope: !93)
+// CHECK:STDOUT: !98 = !DILocation(line: 17, column: 10, scope: !93)
+// CHECK:STDOUT: !99 = !DILocation(line: 17, column: 3, scope: !93)
+// CHECK:STDOUT: !100 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.7776e910959584d9", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !101 = !DILocation(line: 14, column: 7, scope: !100)
+// CHECK:STDOUT: !102 = !DILocation(line: 14, column: 6, scope: !100)
+// CHECK:STDOUT: !103 = !DILocation(line: 15, column: 5, scope: !100)
+// CHECK:STDOUT: !104 = !DILocation(line: 17, column: 21, scope: !100)
+// CHECK:STDOUT: !105 = !DILocation(line: 17, column: 10, scope: !100)
+// CHECK:STDOUT: !106 = !DILocation(line: 17, column: 3, scope: !100)
+// CHECK:STDOUT: !107 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.bea8bae6e14e4034", scope: null, file: !3, line: 13, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !108 = !DILocation(line: 14, column: 7, scope: !107)
+// CHECK:STDOUT: !109 = !DILocation(line: 14, column: 6, scope: !107)
+// CHECK:STDOUT: !110 = !DILocation(line: 15, column: 5, scope: !107)
+// CHECK:STDOUT: !111 = !DILocation(line: 17, column: 21, scope: !107)
+// CHECK:STDOUT: !112 = !DILocation(line: 17, column: 10, scope: !107)
+// CHECK:STDOUT: !113 = !DILocation(line: 17, column: 3, scope: !107)

+ 192 - 296
toolchain/lower/testdata/function/generic/call_recursive_sccs_deep.carbon

@@ -105,7 +105,7 @@ fn M() {
 // CHECK:STDOUT:   %.loc79_5 = load ptr, ptr %ptr_i32.var, align 8, !dbg !15
 // CHECK:STDOUT:   %A.call.loc79 = call ptr @_CA.Main.e8193710fd35b608(ptr %.loc79_5, i32 0), !dbg !16
 // CHECK:STDOUT:   %.loc80_5 = load ptr, ptr %ptr_f64.var, align 8, !dbg !17
-// CHECK:STDOUT:   %A.call.loc80 = call ptr @_CA.Main.04bf2edaaa84aa22(ptr %.loc80_5, i32 0), !dbg !18
+// CHECK:STDOUT:   %A.call.loc80 = call ptr @_CA.Main.e8193710fd35b608(ptr %.loc80_5, i32 0), !dbg !18
 // CHECK:STDOUT:   ret void, !dbg !19
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
@@ -133,270 +133,201 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %D.call, !dbg !31
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CA.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !32 {
+// CHECK:STDOUT: define linkonce_odr void @_CB.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !32 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   call void @_CB.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !33
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !34
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !35
+// CHECK:STDOUT:   call void @_CC.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !33
+// CHECK:STDOUT:   ret void, !dbg !34
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CB.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !36 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !35 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   call void @_CC.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !37
-// CHECK:STDOUT:   ret void, !dbg !38
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !39 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !40
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !41
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   ret i32 %x, !dbg !42
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !43
-// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !43
-// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !44
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %E.call = call i32 @_CE.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !45
-// CHECK:STDOUT:   ret i32 %E.call, !dbg !46
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !47
-// CHECK:STDOUT:   ret i32 %F.call, !dbg !48
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CB.Main.66be507887ceee78(double %x, i32 %count) !dbg !49 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   call void @_CC.Main.66be507887ceee78(double %x, i32 %count), !dbg !50
-// CHECK:STDOUT:   ret void, !dbg !51
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CD.Main.66be507887ceee78(double %x, i32 %count) !dbg !52 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !53
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !54
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !36
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !37
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   ret double %x, !dbg !55
+// CHECK:STDOUT:   ret i32 %x, !dbg !38
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !56
-// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !56
-// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !57
+// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !39
+// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !39
+// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !40
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %E.call = call double @_CE.Main.66be507887ceee78(double %x, i32 %count), !dbg !58
-// CHECK:STDOUT:   ret double %E.call, !dbg !59
+// CHECK:STDOUT:   %E.call = call i32 @_CE.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !41
+// CHECK:STDOUT:   ret i32 %E.call, !dbg !42
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %F.call = call double @_CF.Main.66be507887ceee78(double %x, i32 %count), !dbg !60
-// CHECK:STDOUT:   ret double %F.call, !dbg !61
+// CHECK:STDOUT:   %F.call = call i32 @_CF.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !43
+// CHECK:STDOUT:   ret i32 %F.call, !dbg !44
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CB.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !62 {
+// CHECK:STDOUT: define linkonce_odr void @_CB.Main.66be507887ceee78(double %x, i32 %count) !dbg !45 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   call void @_CC.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !63
-// CHECK:STDOUT:   ret void, !dbg !64
+// CHECK:STDOUT:   call void @_CC.Main.66be507887ceee78(double %x, i32 %count), !dbg !46
+// CHECK:STDOUT:   ret void, !dbg !47
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !65 {
+// CHECK:STDOUT: define linkonce_odr double @_CD.Main.66be507887ceee78(double %x, i32 %count) !dbg !48 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !66
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !67
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !49
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !50
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !68
+// CHECK:STDOUT:   ret double %x, !dbg !51
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !69
-// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !69
-// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !70
+// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !52
+// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !52
+// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !53
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %E.call = call ptr @_CE.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !71
-// CHECK:STDOUT:   ret ptr %E.call, !dbg !72
+// CHECK:STDOUT:   %E.call = call double @_CE.Main.66be507887ceee78(double %x, i32 %count), !dbg !54
+// CHECK:STDOUT:   ret double %E.call, !dbg !55
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !73
-// CHECK:STDOUT:   ret ptr %F.call, !dbg !74
+// CHECK:STDOUT:   %F.call = call double @_CF.Main.66be507887ceee78(double %x, i32 %count), !dbg !56
+// CHECK:STDOUT:   ret double %F.call, !dbg !57
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CB.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !75 {
+// CHECK:STDOUT: define linkonce_odr void @_CB.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !58 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   call void @_CC.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !76
-// CHECK:STDOUT:   ret void, !dbg !77
+// CHECK:STDOUT:   call void @_CC.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !59
+// CHECK:STDOUT:   ret void, !dbg !60
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !78 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !61 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !79
-// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !80
+// CHECK:STDOUT:   %int.greater = icmp sgt i32 %count, 4, !dbg !62
+// CHECK:STDOUT:   br i1 %int.greater, label %if.then.loc46, label %if.else.loc46, !dbg !63
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   ret ptr %x, !dbg !81
+// CHECK:STDOUT:   ret ptr %x, !dbg !64
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else.loc46:                                    ; preds = %entry
-// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !82
-// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !82
-// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !83
+// CHECK:STDOUT:   %int.smod = srem i32 %count, 2, !dbg !65
+// CHECK:STDOUT:   %int.eq = icmp eq i32 %int.smod, 0, !dbg !65
+// CHECK:STDOUT:   br i1 %int.eq, label %if.then.loc49, label %if.else.loc49, !dbg !66
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %E.call = call ptr @_CE.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !84
-// CHECK:STDOUT:   ret ptr %E.call, !dbg !85
+// CHECK:STDOUT:   %E.call = call ptr @_CE.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !67
+// CHECK:STDOUT:   ret ptr %E.call, !dbg !68
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else.loc49:                                    ; preds = %if.else.loc46
-// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !86
-// CHECK:STDOUT:   ret ptr %F.call, !dbg !87
+// CHECK:STDOUT:   %F.call = call ptr @_CF.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !69
+// CHECK:STDOUT:   ret ptr %F.call, !dbg !70
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CC.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !88 {
+// CHECK:STDOUT: define linkonce_odr void @_CC.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !71 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !89
-// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !90
+// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !72
+// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !73
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !91
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !92
-// CHECK:STDOUT:   call void @_CB.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !93
-// CHECK:STDOUT:   br label %if.else, !dbg !94
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !74
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !75
+// CHECK:STDOUT:   call void @_CB.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !76
+// CHECK:STDOUT:   br label %if.else, !dbg !77
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else:                                          ; preds = %if.then, %entry
-// CHECK:STDOUT:   ret void, !dbg !95
+// CHECK:STDOUT:   ret void, !dbg !78
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CE.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !96 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CE.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !79 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !97
-// CHECK:STDOUT:   ret i32 %G.call, !dbg !98
+// CHECK:STDOUT:   %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !80
+// CHECK:STDOUT:   ret i32 %G.call, !dbg !81
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !99 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !82 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !100
-// CHECK:STDOUT:   ret i32 %G.call, !dbg !101
+// CHECK:STDOUT:   %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count), !dbg !83
+// CHECK:STDOUT:   ret i32 %G.call, !dbg !84
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CC.Main.66be507887ceee78(double %x, i32 %count) !dbg !102 {
+// CHECK:STDOUT: define linkonce_odr void @_CC.Main.66be507887ceee78(double %x, i32 %count) !dbg !85 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !103
-// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !104
+// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !86
+// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !87
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !105
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !106
-// CHECK:STDOUT:   call void @_CB.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !107
-// CHECK:STDOUT:   br label %if.else, !dbg !108
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !88
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !89
+// CHECK:STDOUT:   call void @_CB.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !90
+// CHECK:STDOUT:   br label %if.else, !dbg !91
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else:                                          ; preds = %if.then, %entry
-// CHECK:STDOUT:   ret void, !dbg !109
+// CHECK:STDOUT:   ret void, !dbg !92
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CE.Main.66be507887ceee78(double %x, i32 %count) !dbg !110 {
+// CHECK:STDOUT: define linkonce_odr double @_CE.Main.66be507887ceee78(double %x, i32 %count) !dbg !93 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call double @_CG.Main.66be507887ceee78(double %x, i32 %count), !dbg !111
-// CHECK:STDOUT:   ret double %G.call, !dbg !112
+// CHECK:STDOUT:   %G.call = call double @_CG.Main.66be507887ceee78(double %x, i32 %count), !dbg !94
+// CHECK:STDOUT:   ret double %G.call, !dbg !95
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CF.Main.66be507887ceee78(double %x, i32 %count) !dbg !113 {
+// CHECK:STDOUT: define linkonce_odr double @_CF.Main.66be507887ceee78(double %x, i32 %count) !dbg !96 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call double @_CG.Main.66be507887ceee78(double %x, i32 %count), !dbg !114
-// CHECK:STDOUT:   ret double %G.call, !dbg !115
+// CHECK:STDOUT:   %G.call = call double @_CG.Main.66be507887ceee78(double %x, i32 %count), !dbg !97
+// CHECK:STDOUT:   ret double %G.call, !dbg !98
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CC.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !116 {
+// CHECK:STDOUT: define linkonce_odr void @_CC.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !99 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !117
-// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !118
+// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !100
+// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !101
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !119
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !120
-// CHECK:STDOUT:   call void @_CB.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !121
-// CHECK:STDOUT:   br label %if.else, !dbg !122
+// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !102
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !103
+// CHECK:STDOUT:   call void @_CB.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !104
+// CHECK:STDOUT:   br label %if.else, !dbg !105
 // CHECK:STDOUT:
 // CHECK:STDOUT: if.else:                                          ; preds = %if.then, %entry
-// CHECK:STDOUT:   ret void, !dbg !123
+// CHECK:STDOUT:   ret void, !dbg !106
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CE.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !124 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CE.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !107 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !125
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !126
+// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !108
+// CHECK:STDOUT:   ret ptr %G.call, !dbg !109
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !127 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !110 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !128
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !129
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr void @_CC.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !130 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.less_eq = icmp sle i32 %count, 2, !dbg !131
-// CHECK:STDOUT:   br i1 %int.less_eq, label %if.then, label %if.else, !dbg !132
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.then:                                          ; preds = %entry
-// CHECK:STDOUT:   %print.int = call i32 (ptr, ...) @printf(ptr @printf.int.format, i32 %count), !dbg !133
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !134
-// CHECK:STDOUT:   call void @_CB.Main.04bf2edaaa84aa22(ptr %x, i32 %int.sadd), !dbg !135
-// CHECK:STDOUT:   br label %if.else, !dbg !136
-// CHECK:STDOUT:
-// CHECK:STDOUT: if.else:                                          ; preds = %if.then, %entry
-// CHECK:STDOUT:   ret void, !dbg !137
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CE.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !138 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !139
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !140
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !141 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.04bf2edaaa84aa22(ptr %x, i32 %count), !dbg !142
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !143
+// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count), !dbg !111
+// CHECK:STDOUT:   ret ptr %G.call, !dbg !112
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: declare i32 @printf(ptr, ...)
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !144 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !145
-// CHECK:STDOUT:   %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !146
-// CHECK:STDOUT:   ret i32 %D.call, !dbg !147
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CG.Main.66be507887ceee78(double %x, i32 %count) !dbg !148 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x, i32 %count) !dbg !113 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !149
-// CHECK:STDOUT:   %D.call = call double @_CD.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !150
-// CHECK:STDOUT:   ret double %D.call, !dbg !151
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !114
+// CHECK:STDOUT:   %D.call = call i32 @_CD.Main.b88d1103f417c6d4(i32 %x, i32 %int.sadd), !dbg !115
+// CHECK:STDOUT:   ret i32 %D.call, !dbg !116
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !152 {
+// CHECK:STDOUT: define linkonce_odr double @_CG.Main.66be507887ceee78(double %x, i32 %count) !dbg !117 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !153
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !154
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !155
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !118
+// CHECK:STDOUT:   %D.call = call double @_CD.Main.66be507887ceee78(double %x, i32 %int.sadd), !dbg !119
+// CHECK:STDOUT:   ret double %D.call, !dbg !120
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.04bf2edaaa84aa22(ptr %x, i32 %count) !dbg !156 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.e8193710fd35b608(ptr %x, i32 %count) !dbg !121 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !157
-// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.04bf2edaaa84aa22(ptr %x, i32 %int.sadd), !dbg !158
-// CHECK:STDOUT:   ret ptr %D.call, !dbg !159
+// CHECK:STDOUT:   %int.sadd = add i32 %count, 1, !dbg !122
+// CHECK:STDOUT:   %D.call = call ptr @_CD.Main.e8193710fd35b608(ptr %x, i32 %int.sadd), !dbg !123
+// CHECK:STDOUT:   ret ptr %D.call, !dbg !124
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
 // CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 3, 2, 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @printf, { 3, 2, 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @_CA.Main.e8193710fd35b608, { 1, 0 }
+// CHECK:STDOUT: uselistorder ptr @printf, { 2, 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CG.Main.b88d1103f417c6d4, { 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CG.Main.66be507887ceee78, { 1, 0 }
 // CHECK:STDOUT: uselistorder ptr @_CG.Main.e8193710fd35b608, { 1, 0 }
-// CHECK:STDOUT: uselistorder ptr @_CG.Main.04bf2edaaa84aa22, { 1, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT:
@@ -435,131 +366,96 @@ fn M() {
 // CHECK:STDOUT: !29 = !DILocation(line: 30, column: 3, scope: !28)
 // CHECK:STDOUT: !30 = !DILocation(line: 31, column: 10, scope: !28)
 // CHECK:STDOUT: !31 = !DILocation(line: 31, column: 3, scope: !28)
-// CHECK:STDOUT: !32 = distinct !DISubprogram(name: "A", linkageName: "_CA.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 29, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !33 = !DILocation(line: 30, column: 3, scope: !32)
-// CHECK:STDOUT: !34 = !DILocation(line: 31, column: 10, scope: !32)
-// CHECK:STDOUT: !35 = !DILocation(line: 31, column: 3, scope: !32)
-// CHECK:STDOUT: !36 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.b88d1103f417c6d4", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !37 = !DILocation(line: 35, column: 3, scope: !36)
-// CHECK:STDOUT: !38 = !DILocation(line: 34, column: 1, scope: !36)
-// CHECK:STDOUT: !39 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.b88d1103f417c6d4", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !40 = !DILocation(line: 46, column: 7, scope: !39)
-// CHECK:STDOUT: !41 = !DILocation(line: 46, column: 6, scope: !39)
-// CHECK:STDOUT: !42 = !DILocation(line: 47, column: 5, scope: !39)
-// CHECK:STDOUT: !43 = !DILocation(line: 49, column: 7, scope: !39)
-// CHECK:STDOUT: !44 = !DILocation(line: 49, column: 6, scope: !39)
-// CHECK:STDOUT: !45 = !DILocation(line: 50, column: 12, scope: !39)
-// CHECK:STDOUT: !46 = !DILocation(line: 50, column: 5, scope: !39)
-// CHECK:STDOUT: !47 = !DILocation(line: 52, column: 12, scope: !39)
-// CHECK:STDOUT: !48 = !DILocation(line: 52, column: 5, scope: !39)
-// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.66be507887ceee78", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !50 = !DILocation(line: 35, column: 3, scope: !49)
-// CHECK:STDOUT: !51 = !DILocation(line: 34, column: 1, scope: !49)
-// CHECK:STDOUT: !52 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.66be507887ceee78", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !53 = !DILocation(line: 46, column: 7, scope: !52)
-// CHECK:STDOUT: !54 = !DILocation(line: 46, column: 6, scope: !52)
-// CHECK:STDOUT: !55 = !DILocation(line: 47, column: 5, scope: !52)
-// CHECK:STDOUT: !56 = !DILocation(line: 49, column: 7, scope: !52)
-// CHECK:STDOUT: !57 = !DILocation(line: 49, column: 6, scope: !52)
-// CHECK:STDOUT: !58 = !DILocation(line: 50, column: 12, scope: !52)
-// CHECK:STDOUT: !59 = !DILocation(line: 50, column: 5, scope: !52)
-// CHECK:STDOUT: !60 = !DILocation(line: 52, column: 12, scope: !52)
-// CHECK:STDOUT: !61 = !DILocation(line: 52, column: 5, scope: !52)
-// CHECK:STDOUT: !62 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.e8193710fd35b608", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !63 = !DILocation(line: 35, column: 3, scope: !62)
-// CHECK:STDOUT: !64 = !DILocation(line: 34, column: 1, scope: !62)
-// CHECK:STDOUT: !65 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.e8193710fd35b608", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !66 = !DILocation(line: 46, column: 7, scope: !65)
-// CHECK:STDOUT: !67 = !DILocation(line: 46, column: 6, scope: !65)
-// CHECK:STDOUT: !68 = !DILocation(line: 47, column: 5, scope: !65)
-// CHECK:STDOUT: !69 = !DILocation(line: 49, column: 7, scope: !65)
-// CHECK:STDOUT: !70 = !DILocation(line: 49, column: 6, scope: !65)
-// CHECK:STDOUT: !71 = !DILocation(line: 50, column: 12, scope: !65)
-// CHECK:STDOUT: !72 = !DILocation(line: 50, column: 5, scope: !65)
-// CHECK:STDOUT: !73 = !DILocation(line: 52, column: 12, scope: !65)
-// CHECK:STDOUT: !74 = !DILocation(line: 52, column: 5, scope: !65)
-// CHECK:STDOUT: !75 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !76 = !DILocation(line: 35, column: 3, scope: !75)
-// CHECK:STDOUT: !77 = !DILocation(line: 34, column: 1, scope: !75)
-// CHECK:STDOUT: !78 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !79 = !DILocation(line: 46, column: 7, scope: !78)
-// CHECK:STDOUT: !80 = !DILocation(line: 46, column: 6, scope: !78)
-// CHECK:STDOUT: !81 = !DILocation(line: 47, column: 5, scope: !78)
-// CHECK:STDOUT: !82 = !DILocation(line: 49, column: 7, scope: !78)
-// CHECK:STDOUT: !83 = !DILocation(line: 49, column: 6, scope: !78)
-// CHECK:STDOUT: !84 = !DILocation(line: 50, column: 12, scope: !78)
-// CHECK:STDOUT: !85 = !DILocation(line: 50, column: 5, scope: !78)
-// CHECK:STDOUT: !86 = !DILocation(line: 52, column: 12, scope: !78)
-// CHECK:STDOUT: !87 = !DILocation(line: 52, column: 5, scope: !78)
-// CHECK:STDOUT: !88 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.b88d1103f417c6d4", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !89 = !DILocation(line: 39, column: 7, scope: !88)
-// CHECK:STDOUT: !90 = !DILocation(line: 39, column: 6, scope: !88)
-// CHECK:STDOUT: !91 = !DILocation(line: 40, column: 5, scope: !88)
-// CHECK:STDOUT: !92 = !DILocation(line: 41, column: 10, scope: !88)
-// CHECK:STDOUT: !93 = !DILocation(line: 41, column: 5, scope: !88)
-// CHECK:STDOUT: !94 = !DILocation(line: 39, column: 3, scope: !88)
-// CHECK:STDOUT: !95 = !DILocation(line: 38, column: 1, scope: !88)
-// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.b88d1103f417c6d4", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !97 = !DILocation(line: 59, column: 10, scope: !96)
-// CHECK:STDOUT: !98 = !DILocation(line: 59, column: 3, scope: !96)
-// CHECK:STDOUT: !99 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !100 = !DILocation(line: 63, column: 10, scope: !99)
-// CHECK:STDOUT: !101 = !DILocation(line: 63, column: 3, scope: !99)
-// CHECK:STDOUT: !102 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.66be507887ceee78", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !103 = !DILocation(line: 39, column: 7, scope: !102)
-// CHECK:STDOUT: !104 = !DILocation(line: 39, column: 6, scope: !102)
-// CHECK:STDOUT: !105 = !DILocation(line: 40, column: 5, scope: !102)
-// CHECK:STDOUT: !106 = !DILocation(line: 41, column: 10, scope: !102)
-// CHECK:STDOUT: !107 = !DILocation(line: 41, column: 5, scope: !102)
-// CHECK:STDOUT: !108 = !DILocation(line: 39, column: 3, scope: !102)
-// CHECK:STDOUT: !109 = !DILocation(line: 38, column: 1, scope: !102)
-// CHECK:STDOUT: !110 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.66be507887ceee78", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !111 = !DILocation(line: 59, column: 10, scope: !110)
-// CHECK:STDOUT: !112 = !DILocation(line: 59, column: 3, scope: !110)
-// CHECK:STDOUT: !113 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !114 = !DILocation(line: 63, column: 10, scope: !113)
-// CHECK:STDOUT: !115 = !DILocation(line: 63, column: 3, scope: !113)
-// CHECK:STDOUT: !116 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.e8193710fd35b608", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !117 = !DILocation(line: 39, column: 7, scope: !116)
-// CHECK:STDOUT: !118 = !DILocation(line: 39, column: 6, scope: !116)
-// CHECK:STDOUT: !119 = !DILocation(line: 40, column: 5, scope: !116)
-// CHECK:STDOUT: !120 = !DILocation(line: 41, column: 10, scope: !116)
-// CHECK:STDOUT: !121 = !DILocation(line: 41, column: 5, scope: !116)
-// CHECK:STDOUT: !122 = !DILocation(line: 39, column: 3, scope: !116)
-// CHECK:STDOUT: !123 = !DILocation(line: 38, column: 1, scope: !116)
-// CHECK:STDOUT: !124 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.e8193710fd35b608", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !125 = !DILocation(line: 59, column: 10, scope: !124)
-// CHECK:STDOUT: !126 = !DILocation(line: 59, column: 3, scope: !124)
-// CHECK:STDOUT: !127 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.e8193710fd35b608", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !128 = !DILocation(line: 63, column: 10, scope: !127)
-// CHECK:STDOUT: !129 = !DILocation(line: 63, column: 3, scope: !127)
-// CHECK:STDOUT: !130 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !131 = !DILocation(line: 39, column: 7, scope: !130)
-// CHECK:STDOUT: !132 = !DILocation(line: 39, column: 6, scope: !130)
-// CHECK:STDOUT: !133 = !DILocation(line: 40, column: 5, scope: !130)
-// CHECK:STDOUT: !134 = !DILocation(line: 41, column: 10, scope: !130)
-// CHECK:STDOUT: !135 = !DILocation(line: 41, column: 5, scope: !130)
-// CHECK:STDOUT: !136 = !DILocation(line: 39, column: 3, scope: !130)
-// CHECK:STDOUT: !137 = !DILocation(line: 38, column: 1, scope: !130)
-// CHECK:STDOUT: !138 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !139 = !DILocation(line: 59, column: 10, scope: !138)
-// CHECK:STDOUT: !140 = !DILocation(line: 59, column: 3, scope: !138)
-// CHECK:STDOUT: !141 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !142 = !DILocation(line: 63, column: 10, scope: !141)
-// CHECK:STDOUT: !143 = !DILocation(line: 63, column: 3, scope: !141)
-// CHECK:STDOUT: !144 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !145 = !DILocation(line: 67, column: 15, scope: !144)
-// CHECK:STDOUT: !146 = !DILocation(line: 67, column: 10, scope: !144)
-// CHECK:STDOUT: !147 = !DILocation(line: 67, column: 3, scope: !144)
-// CHECK:STDOUT: !148 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !149 = !DILocation(line: 67, column: 15, scope: !148)
-// CHECK:STDOUT: !150 = !DILocation(line: 67, column: 10, scope: !148)
-// CHECK:STDOUT: !151 = !DILocation(line: 67, column: 3, scope: !148)
-// CHECK:STDOUT: !152 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e8193710fd35b608", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !153 = !DILocation(line: 67, column: 15, scope: !152)
-// CHECK:STDOUT: !154 = !DILocation(line: 67, column: 10, scope: !152)
-// CHECK:STDOUT: !155 = !DILocation(line: 67, column: 3, scope: !152)
-// CHECK:STDOUT: !156 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !157 = !DILocation(line: 67, column: 15, scope: !156)
-// CHECK:STDOUT: !158 = !DILocation(line: 67, column: 10, scope: !156)
-// CHECK:STDOUT: !159 = !DILocation(line: 67, column: 3, scope: !156)
+// CHECK:STDOUT: !32 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.b88d1103f417c6d4", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !33 = !DILocation(line: 35, column: 3, scope: !32)
+// CHECK:STDOUT: !34 = !DILocation(line: 34, column: 1, scope: !32)
+// CHECK:STDOUT: !35 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.b88d1103f417c6d4", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !36 = !DILocation(line: 46, column: 7, scope: !35)
+// CHECK:STDOUT: !37 = !DILocation(line: 46, column: 6, scope: !35)
+// CHECK:STDOUT: !38 = !DILocation(line: 47, column: 5, scope: !35)
+// CHECK:STDOUT: !39 = !DILocation(line: 49, column: 7, scope: !35)
+// CHECK:STDOUT: !40 = !DILocation(line: 49, column: 6, scope: !35)
+// CHECK:STDOUT: !41 = !DILocation(line: 50, column: 12, scope: !35)
+// CHECK:STDOUT: !42 = !DILocation(line: 50, column: 5, scope: !35)
+// CHECK:STDOUT: !43 = !DILocation(line: 52, column: 12, scope: !35)
+// CHECK:STDOUT: !44 = !DILocation(line: 52, column: 5, scope: !35)
+// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.66be507887ceee78", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !46 = !DILocation(line: 35, column: 3, scope: !45)
+// CHECK:STDOUT: !47 = !DILocation(line: 34, column: 1, scope: !45)
+// CHECK:STDOUT: !48 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.66be507887ceee78", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !49 = !DILocation(line: 46, column: 7, scope: !48)
+// CHECK:STDOUT: !50 = !DILocation(line: 46, column: 6, scope: !48)
+// CHECK:STDOUT: !51 = !DILocation(line: 47, column: 5, scope: !48)
+// CHECK:STDOUT: !52 = !DILocation(line: 49, column: 7, scope: !48)
+// CHECK:STDOUT: !53 = !DILocation(line: 49, column: 6, scope: !48)
+// CHECK:STDOUT: !54 = !DILocation(line: 50, column: 12, scope: !48)
+// CHECK:STDOUT: !55 = !DILocation(line: 50, column: 5, scope: !48)
+// CHECK:STDOUT: !56 = !DILocation(line: 52, column: 12, scope: !48)
+// CHECK:STDOUT: !57 = !DILocation(line: 52, column: 5, scope: !48)
+// CHECK:STDOUT: !58 = distinct !DISubprogram(name: "B", linkageName: "_CB.Main.e8193710fd35b608", scope: null, file: !3, line: 34, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !59 = !DILocation(line: 35, column: 3, scope: !58)
+// CHECK:STDOUT: !60 = !DILocation(line: 34, column: 1, scope: !58)
+// CHECK:STDOUT: !61 = distinct !DISubprogram(name: "D", linkageName: "_CD.Main.e8193710fd35b608", scope: null, file: !3, line: 45, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !62 = !DILocation(line: 46, column: 7, scope: !61)
+// CHECK:STDOUT: !63 = !DILocation(line: 46, column: 6, scope: !61)
+// CHECK:STDOUT: !64 = !DILocation(line: 47, column: 5, scope: !61)
+// CHECK:STDOUT: !65 = !DILocation(line: 49, column: 7, scope: !61)
+// CHECK:STDOUT: !66 = !DILocation(line: 49, column: 6, scope: !61)
+// CHECK:STDOUT: !67 = !DILocation(line: 50, column: 12, scope: !61)
+// CHECK:STDOUT: !68 = !DILocation(line: 50, column: 5, scope: !61)
+// CHECK:STDOUT: !69 = !DILocation(line: 52, column: 12, scope: !61)
+// CHECK:STDOUT: !70 = !DILocation(line: 52, column: 5, scope: !61)
+// CHECK:STDOUT: !71 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.b88d1103f417c6d4", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !72 = !DILocation(line: 39, column: 7, scope: !71)
+// CHECK:STDOUT: !73 = !DILocation(line: 39, column: 6, scope: !71)
+// CHECK:STDOUT: !74 = !DILocation(line: 40, column: 5, scope: !71)
+// CHECK:STDOUT: !75 = !DILocation(line: 41, column: 10, scope: !71)
+// CHECK:STDOUT: !76 = !DILocation(line: 41, column: 5, scope: !71)
+// CHECK:STDOUT: !77 = !DILocation(line: 39, column: 3, scope: !71)
+// CHECK:STDOUT: !78 = !DILocation(line: 38, column: 1, scope: !71)
+// CHECK:STDOUT: !79 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.b88d1103f417c6d4", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !80 = !DILocation(line: 59, column: 10, scope: !79)
+// CHECK:STDOUT: !81 = !DILocation(line: 59, column: 3, scope: !79)
+// CHECK:STDOUT: !82 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !83 = !DILocation(line: 63, column: 10, scope: !82)
+// CHECK:STDOUT: !84 = !DILocation(line: 63, column: 3, scope: !82)
+// CHECK:STDOUT: !85 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.66be507887ceee78", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !86 = !DILocation(line: 39, column: 7, scope: !85)
+// CHECK:STDOUT: !87 = !DILocation(line: 39, column: 6, scope: !85)
+// CHECK:STDOUT: !88 = !DILocation(line: 40, column: 5, scope: !85)
+// CHECK:STDOUT: !89 = !DILocation(line: 41, column: 10, scope: !85)
+// CHECK:STDOUT: !90 = !DILocation(line: 41, column: 5, scope: !85)
+// CHECK:STDOUT: !91 = !DILocation(line: 39, column: 3, scope: !85)
+// CHECK:STDOUT: !92 = !DILocation(line: 38, column: 1, scope: !85)
+// CHECK:STDOUT: !93 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.66be507887ceee78", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !94 = !DILocation(line: 59, column: 10, scope: !93)
+// CHECK:STDOUT: !95 = !DILocation(line: 59, column: 3, scope: !93)
+// CHECK:STDOUT: !96 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !97 = !DILocation(line: 63, column: 10, scope: !96)
+// CHECK:STDOUT: !98 = !DILocation(line: 63, column: 3, scope: !96)
+// CHECK:STDOUT: !99 = distinct !DISubprogram(name: "C", linkageName: "_CC.Main.e8193710fd35b608", scope: null, file: !3, line: 38, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !100 = !DILocation(line: 39, column: 7, scope: !99)
+// CHECK:STDOUT: !101 = !DILocation(line: 39, column: 6, scope: !99)
+// CHECK:STDOUT: !102 = !DILocation(line: 40, column: 5, scope: !99)
+// CHECK:STDOUT: !103 = !DILocation(line: 41, column: 10, scope: !99)
+// CHECK:STDOUT: !104 = !DILocation(line: 41, column: 5, scope: !99)
+// CHECK:STDOUT: !105 = !DILocation(line: 39, column: 3, scope: !99)
+// CHECK:STDOUT: !106 = !DILocation(line: 38, column: 1, scope: !99)
+// CHECK:STDOUT: !107 = distinct !DISubprogram(name: "E", linkageName: "_CE.Main.e8193710fd35b608", scope: null, file: !3, line: 58, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !108 = !DILocation(line: 59, column: 10, scope: !107)
+// CHECK:STDOUT: !109 = !DILocation(line: 59, column: 3, scope: !107)
+// CHECK:STDOUT: !110 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.e8193710fd35b608", scope: null, file: !3, line: 62, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !111 = !DILocation(line: 63, column: 10, scope: !110)
+// CHECK:STDOUT: !112 = !DILocation(line: 63, column: 3, scope: !110)
+// CHECK:STDOUT: !113 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !114 = !DILocation(line: 67, column: 15, scope: !113)
+// CHECK:STDOUT: !115 = !DILocation(line: 67, column: 10, scope: !113)
+// CHECK:STDOUT: !116 = !DILocation(line: 67, column: 3, scope: !113)
+// CHECK:STDOUT: !117 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !118 = !DILocation(line: 67, column: 15, scope: !117)
+// CHECK:STDOUT: !119 = !DILocation(line: 67, column: 10, scope: !117)
+// CHECK:STDOUT: !120 = !DILocation(line: 67, column: 3, scope: !117)
+// CHECK:STDOUT: !121 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e8193710fd35b608", scope: null, file: !3, line: 66, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !122 = !DILocation(line: 67, column: 15, scope: !121)
+// CHECK:STDOUT: !123 = !DILocation(line: 67, column: 10, scope: !121)
+// CHECK:STDOUT: !124 = !DILocation(line: 67, column: 3, scope: !121)

+ 68 - 123
toolchain/lower/testdata/function/generic/call_specific_in_class.carbon

@@ -60,10 +60,10 @@ fn M() {
 // CHECK:STDOUT:   %F.call.loc32 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc32), !dbg !14
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_f64.var), !dbg !8
 // CHECK:STDOUT:   %.loc34 = load ptr, ptr %ptr_f64.var, align 8, !dbg !15
-// CHECK:STDOUT:   %F.call.loc34 = call ptr @_CF.Main.04bf2edaaa84aa22(ptr %.loc34), !dbg !16
+// CHECK:STDOUT:   %F.call.loc34 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc34), !dbg !16
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 8, ptr %ptr_i8.var), !dbg !9
 // CHECK:STDOUT:   %.loc36 = load ptr, ptr %ptr_i8.var, align 8, !dbg !17
-// CHECK:STDOUT:   %F.call.loc36 = call ptr @_CF.Main.bda010de15e6a5ad(ptr %.loc36), !dbg !18
+// CHECK:STDOUT:   %F.call.loc36 = call ptr @_CF.Main.e8193710fd35b608(ptr %.loc36), !dbg !18
 // CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 4, ptr %var_i32.var), !dbg !10
 // CHECK:STDOUT:   store i32 0, ptr %var_i32.var, align 4, !dbg !10
 // CHECK:STDOUT:   %.loc38 = load i32, ptr %var_i32.var, align 4, !dbg !19
@@ -86,116 +86,79 @@ fn M() {
 // CHECK:STDOUT:   ret ptr %G.call, !dbg !27
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.04bf2edaaa84aa22(ptr %x) !dbg !28 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.b88d1103f417c6d4(i32 %x) !dbg !28 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.04bf2edaaa84aa22(ptr %x), !dbg !29
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !30
+// CHECK:STDOUT:   %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %x), !dbg !29
+// CHECK:STDOUT:   ret i32 %G.call, !dbg !30
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CF.Main.bda010de15e6a5ad(ptr %x) !dbg !31 {
+// CHECK:STDOUT: define linkonce_odr double @_CF.Main.66be507887ceee78(double %x) !dbg !31 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call ptr @_CG.Main.bda010de15e6a5ad(ptr %x), !dbg !32
-// CHECK:STDOUT:   ret ptr %G.call, !dbg !33
+// CHECK:STDOUT:   %G.call = call double @_CG.Main.66be507887ceee78(double %x), !dbg !32
+// CHECK:STDOUT:   ret double %G.call, !dbg !33
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CF.Main.b88d1103f417c6d4(i32 %x) !dbg !34 {
+// CHECK:STDOUT: define linkonce_odr %type @_CF.Main.5754c7a55c7cbe4a(%type %x) !dbg !34 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call i32 @_CG.Main.b88d1103f417c6d4(i32 %x), !dbg !35
-// CHECK:STDOUT:   ret i32 %G.call, !dbg !36
+// CHECK:STDOUT:   %G.call = call %type @_CG.Main.5754c7a55c7cbe4a(%type %x), !dbg !35
+// CHECK:STDOUT:   ret %type %G.call, !dbg !36
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CF.Main.66be507887ceee78(double %x) !dbg !37 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.e8193710fd35b608(ptr %x) !dbg !37 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call double @_CG.Main.66be507887ceee78(double %x), !dbg !38
-// CHECK:STDOUT:   ret double %G.call, !dbg !39
+// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !38
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !38
+// CHECK:STDOUT:   %Cfn.call = call ptr @_CCfn.C.Main.e8193710fd35b608(ptr %c.var, ptr %x), !dbg !39
+// CHECK:STDOUT:   ret ptr %Cfn.call, !dbg !40
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr %type @_CF.Main.5754c7a55c7cbe4a(%type %x) !dbg !40 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x) !dbg !41 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %G.call = call %type @_CG.Main.5754c7a55c7cbe4a(%type %x), !dbg !41
-// CHECK:STDOUT:   ret %type %G.call, !dbg !42
+// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !42
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !42
+// CHECK:STDOUT:   %Cfn.call = call i32 @_CCfn.C.Main.b88d1103f417c6d4(ptr %c.var, i32 %x), !dbg !43
+// CHECK:STDOUT:   ret i32 %Cfn.call, !dbg !44
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.e8193710fd35b608(ptr %x) !dbg !43 {
+// CHECK:STDOUT: define linkonce_odr double @_CG.Main.66be507887ceee78(double %x) !dbg !45 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !44
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !44
-// CHECK:STDOUT:   %Cfn.call = call ptr @_CCfn.C.Main.e8193710fd35b608(ptr %c.var, ptr %x), !dbg !45
-// CHECK:STDOUT:   ret ptr %Cfn.call, !dbg !46
+// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !46
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !46
+// CHECK:STDOUT:   %Cfn.call = call double @_CCfn.C.Main.66be507887ceee78(ptr %c.var, double %x), !dbg !47
+// CHECK:STDOUT:   ret double %Cfn.call, !dbg !48
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.04bf2edaaa84aa22(ptr %x) !dbg !47 {
+// CHECK:STDOUT: define linkonce_odr %type @_CG.Main.5754c7a55c7cbe4a(%type %x) !dbg !49 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !48
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !48
-// CHECK:STDOUT:   %Cfn.call = call ptr @_CCfn.C.Main.04bf2edaaa84aa22(ptr %c.var, ptr %x), !dbg !49
-// CHECK:STDOUT:   ret ptr %Cfn.call, !dbg !50
+// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !50
+// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !50
+// CHECK:STDOUT:   %Cfn.call = call %type @_CCfn.C.Main.5754c7a55c7cbe4a(ptr %c.var, %type %x), !dbg !51
+// CHECK:STDOUT:   ret %type %Cfn.call, !dbg !52
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CG.Main.bda010de15e6a5ad(ptr %x) !dbg !51 {
+// CHECK:STDOUT: define linkonce_odr ptr @_CCfn.C.Main.e8193710fd35b608(ptr %self, ptr %x) !dbg !53 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !52
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !52
-// CHECK:STDOUT:   %Cfn.call = call ptr @_CCfn.C.Main.bda010de15e6a5ad(ptr %c.var, ptr %x), !dbg !53
-// CHECK:STDOUT:   ret ptr %Cfn.call, !dbg !54
+// CHECK:STDOUT:   ret ptr %x, !dbg !54
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CG.Main.b88d1103f417c6d4(i32 %x) !dbg !55 {
+// CHECK:STDOUT: define linkonce_odr i32 @_CCfn.C.Main.b88d1103f417c6d4(ptr %self, i32 %x) !dbg !55 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !56
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !56
-// CHECK:STDOUT:   %Cfn.call = call i32 @_CCfn.C.Main.b88d1103f417c6d4(ptr %c.var, i32 %x), !dbg !57
-// CHECK:STDOUT:   ret i32 %Cfn.call, !dbg !58
+// CHECK:STDOUT:   ret i32 %x, !dbg !56
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CG.Main.66be507887ceee78(double %x) !dbg !59 {
+// CHECK:STDOUT: define linkonce_odr double @_CCfn.C.Main.66be507887ceee78(ptr %self, double %x) !dbg !57 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !60
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !60
-// CHECK:STDOUT:   %Cfn.call = call double @_CCfn.C.Main.66be507887ceee78(ptr %c.var, double %x), !dbg !61
-// CHECK:STDOUT:   ret double %Cfn.call, !dbg !62
+// CHECK:STDOUT:   ret double %x, !dbg !58
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr %type @_CG.Main.5754c7a55c7cbe4a(%type %x) !dbg !63 {
+// CHECK:STDOUT: define linkonce_odr %type @_CCfn.C.Main.5754c7a55c7cbe4a(ptr %self, %type %x) !dbg !59 {
 // CHECK:STDOUT: entry:
-// CHECK:STDOUT:   %c.var = alloca {}, align 8, !dbg !64
-// CHECK:STDOUT:   call void @llvm.lifetime.start.p0(i64 0, ptr %c.var), !dbg !64
-// CHECK:STDOUT:   %Cfn.call = call %type @_CCfn.C.Main.5754c7a55c7cbe4a(ptr %c.var, %type %x), !dbg !65
-// CHECK:STDOUT:   ret %type %Cfn.call, !dbg !66
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CCfn.C.Main.e8193710fd35b608(ptr %self, ptr %x) !dbg !67 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !68
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CCfn.C.Main.04bf2edaaa84aa22(ptr %self, ptr %x) !dbg !69 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !70
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr ptr @_CCfn.C.Main.bda010de15e6a5ad(ptr %self, ptr %x) !dbg !71 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret ptr %x, !dbg !72
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr i32 @_CCfn.C.Main.b88d1103f417c6d4(ptr %self, i32 %x) !dbg !73 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret i32 %x, !dbg !74
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr double @_CCfn.C.Main.66be507887ceee78(ptr %self, double %x) !dbg !75 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret double %x, !dbg !76
-// CHECK:STDOUT: }
-// CHECK:STDOUT:
-// CHECK:STDOUT: define linkonce_odr %type @_CCfn.C.Main.5754c7a55c7cbe4a(ptr %self, %type %x) !dbg !77 {
-// CHECK:STDOUT: entry:
-// CHECK:STDOUT:   ret %type %x, !dbg !78
+// CHECK:STDOUT:   ret %type %x, !dbg !60
 // CHECK:STDOUT: }
 // CHECK:STDOUT:
 // CHECK:STDOUT: ; uselistorder directives
-// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 0, 1, 2, 3, 4, 5, 11, 10, 9, 8, 7, 6 }
+// CHECK:STDOUT: uselistorder ptr @llvm.lifetime.start.p0, { 0, 1, 2, 3, 9, 8, 7, 6, 5, 4 }
+// CHECK:STDOUT: uselistorder ptr @_CF.Main.e8193710fd35b608, { 2, 1, 0 }
 // CHECK:STDOUT:
 // CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 // CHECK:STDOUT:
@@ -230,54 +193,36 @@ fn M() {
 // CHECK:STDOUT: !25 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.e8193710fd35b608", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !26 = !DILocation(line: 27, column: 10, scope: !25)
 // CHECK:STDOUT: !27 = !DILocation(line: 27, column: 3, scope: !25)
-// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !28 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !29 = !DILocation(line: 27, column: 10, scope: !28)
 // CHECK:STDOUT: !30 = !DILocation(line: 27, column: 3, scope: !28)
-// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.bda010de15e6a5ad", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !31 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !32 = !DILocation(line: 27, column: 10, scope: !31)
 // CHECK:STDOUT: !33 = !DILocation(line: 27, column: 3, scope: !31)
-// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.b88d1103f417c6d4", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !34 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
 // CHECK:STDOUT: !35 = !DILocation(line: 27, column: 10, scope: !34)
 // CHECK:STDOUT: !36 = !DILocation(line: 27, column: 3, scope: !34)
-// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.66be507887ceee78", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !38 = !DILocation(line: 27, column: 10, scope: !37)
-// CHECK:STDOUT: !39 = !DILocation(line: 27, column: 3, scope: !37)
-// CHECK:STDOUT: !40 = distinct !DISubprogram(name: "F", linkageName: "_CF.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 26, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !41 = !DILocation(line: 27, column: 10, scope: !40)
-// CHECK:STDOUT: !42 = !DILocation(line: 27, column: 3, scope: !40)
-// CHECK:STDOUT: !43 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e8193710fd35b608", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !44 = !DILocation(line: 22, column: 3, scope: !43)
-// CHECK:STDOUT: !45 = !DILocation(line: 23, column: 10, scope: !43)
-// CHECK:STDOUT: !46 = !DILocation(line: 23, column: 3, scope: !43)
-// CHECK:STDOUT: !47 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !48 = !DILocation(line: 22, column: 3, scope: !47)
-// CHECK:STDOUT: !49 = !DILocation(line: 23, column: 10, scope: !47)
-// CHECK:STDOUT: !50 = !DILocation(line: 23, column: 3, scope: !47)
-// CHECK:STDOUT: !51 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.bda010de15e6a5ad", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !52 = !DILocation(line: 22, column: 3, scope: !51)
-// CHECK:STDOUT: !53 = !DILocation(line: 23, column: 10, scope: !51)
-// CHECK:STDOUT: !54 = !DILocation(line: 23, column: 3, scope: !51)
-// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !56 = !DILocation(line: 22, column: 3, scope: !55)
-// CHECK:STDOUT: !57 = !DILocation(line: 23, column: 10, scope: !55)
-// CHECK:STDOUT: !58 = !DILocation(line: 23, column: 3, scope: !55)
-// CHECK:STDOUT: !59 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !60 = !DILocation(line: 22, column: 3, scope: !59)
-// CHECK:STDOUT: !61 = !DILocation(line: 23, column: 10, scope: !59)
-// CHECK:STDOUT: !62 = !DILocation(line: 23, column: 3, scope: !59)
-// CHECK:STDOUT: !63 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !64 = !DILocation(line: 22, column: 3, scope: !63)
-// CHECK:STDOUT: !65 = !DILocation(line: 23, column: 10, scope: !63)
-// CHECK:STDOUT: !66 = !DILocation(line: 23, column: 3, scope: !63)
-// CHECK:STDOUT: !67 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.e8193710fd35b608", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !68 = !DILocation(line: 17, column: 5, scope: !67)
-// CHECK:STDOUT: !69 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.04bf2edaaa84aa22", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !70 = !DILocation(line: 17, column: 5, scope: !69)
-// CHECK:STDOUT: !71 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.bda010de15e6a5ad", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !72 = !DILocation(line: 17, column: 5, scope: !71)
-// CHECK:STDOUT: !73 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.b88d1103f417c6d4", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !74 = !DILocation(line: 17, column: 5, scope: !73)
-// CHECK:STDOUT: !75 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.66be507887ceee78", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !76 = !DILocation(line: 17, column: 5, scope: !75)
-// CHECK:STDOUT: !77 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
-// CHECK:STDOUT: !78 = !DILocation(line: 17, column: 5, scope: !77)
+// CHECK:STDOUT: !37 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.e8193710fd35b608", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !38 = !DILocation(line: 22, column: 3, scope: !37)
+// CHECK:STDOUT: !39 = !DILocation(line: 23, column: 10, scope: !37)
+// CHECK:STDOUT: !40 = !DILocation(line: 23, column: 3, scope: !37)
+// CHECK:STDOUT: !41 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.b88d1103f417c6d4", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !42 = !DILocation(line: 22, column: 3, scope: !41)
+// CHECK:STDOUT: !43 = !DILocation(line: 23, column: 10, scope: !41)
+// CHECK:STDOUT: !44 = !DILocation(line: 23, column: 3, scope: !41)
+// CHECK:STDOUT: !45 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.66be507887ceee78", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !46 = !DILocation(line: 22, column: 3, scope: !45)
+// CHECK:STDOUT: !47 = !DILocation(line: 23, column: 10, scope: !45)
+// CHECK:STDOUT: !48 = !DILocation(line: 23, column: 3, scope: !45)
+// CHECK:STDOUT: !49 = distinct !DISubprogram(name: "G", linkageName: "_CG.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 21, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !50 = !DILocation(line: 22, column: 3, scope: !49)
+// CHECK:STDOUT: !51 = !DILocation(line: 23, column: 10, scope: !49)
+// CHECK:STDOUT: !52 = !DILocation(line: 23, column: 3, scope: !49)
+// CHECK:STDOUT: !53 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.e8193710fd35b608", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !54 = !DILocation(line: 17, column: 5, scope: !53)
+// CHECK:STDOUT: !55 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.b88d1103f417c6d4", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !56 = !DILocation(line: 17, column: 5, scope: !55)
+// CHECK:STDOUT: !57 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.66be507887ceee78", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !58 = !DILocation(line: 17, column: 5, scope: !57)
+// CHECK:STDOUT: !59 = distinct !DISubprogram(name: "Cfn", linkageName: "_CCfn.C.Main.5754c7a55c7cbe4a", scope: null, file: !3, line: 16, type: !5, spFlags: DISPFlagDefinition, unit: !2)
+// CHECK:STDOUT: !60 = !DILocation(line: 17, column: 5, scope: !59)