<commit_before>// RUN: %target-swift-frontend -c -O -enable-copy-propagation=true -enable-lexical-lifetimes=true -sil-verify-all -Xllvm -sil-print-final-ossa-module %s | %FileCheck %s

// REQUIRES: rdar87255563

// =============================================================================
// = DECLARATIONS                                                             {{
// =============================================================================

@_silgen_name("consumeAndProduce")
func consumeAndProduce(_ arg: __owned AnyObject) -> AnyObject

// =============================================================================
// = DECLARATIONS                                                             }}
// =============================================================================

// =============================================================================
// = TESTS                                                                    {{
// =============================================================================

@_silgen_name("eliminate_copy_of_returned_then_consumed_owned_value")
public func eliminate_copy_of_returned_then_consumed_owned_value(arg: __owned AnyObject) {
  // CHECK-LABEL: sil [ossa] @eliminate_copy_of_returned_then_consumed_owned_value : {{.*}} {
  // CHECK:       {{bb[0-9]+}}([[ARG:%[^,]+]] : @owned $AnyObject):
  // retain arg
  // CHECK:       [[ARG_LIFETIME:%[^,]+]] = begin_borrow [lexical] [[ARG]]
  // CHECK:       [[ARG_COPY:%[^,]+]] = copy_value [[ARG_LIFETIME]]
  let x = consumeAndProduce(arg)
  // CHECK:       [[X:%[^,]+]] = apply {{%[^,]+}}([[ARG_COPY]])
  // no copy of 'x'
  _ = consumeAndProduce(x)
  // CHECK:       [[RESULT:%[^,]+]] = apply {{%[^,]+}}([[X]])
  // CHECK:       end_borrow [[ARG_LIFETIME]]
  // release result
  // release arg
  // CHECK:       destroy_value [[RESULT]]
  // CHECK:       destroy_value [[ARG]]
  // CHECK-LABEL: } // end sil function 'eliminate_copy_of_returned_then_consumed_owned_value'<commit_msg>[Test] Reenabled SILOpt/shrink_borrow_scope.<commit_after>// RUN: %target-swift-frontend -c -O -enable-copy-propagation=true -enable-lexical-lifetimes=true -sil-verify-all -Xllvm -sil-print-final-ossa-module %s | %FileCheck %s

// =============================================================================
// = DECLARATIONS                                                             {{
// =============================================================================

@_silgen_name("consumeAndProduce")
func consumeAndProduce(_ arg: __owned AnyObject) -> AnyObject

// =============================================================================
// = DECLARATIONS                                                             }}
// =============================================================================

// =============================================================================
// = TESTS                                                                    {{
// =============================================================================

@_silgen_name("eliminate_copy_of_returned_then_consumed_owned_value")
public func eliminate_copy_of_returned_then_consumed_owned_value(arg: __owned AnyObject) {
  // CHECK-LABEL: sil [ossa] @eliminate_copy_of_returned_then_consumed_owned_value : {{.*}} {
  // CHECK:       {{bb[0-9]+}}([[ARG:%[^,]+]] : @owned $AnyObject):
  // retain arg
  // CHECK:       [[ARG_LIFETIME:%[^,]+]] = begin_borrow [lexical] [[ARG]]
  // CHECK:       [[ARG_COPY:%[^,]+]] = copy_value [[ARG_LIFETIME]]
  let x = consumeAndProduce(arg)
  // CHECK:       [[X:%[^,]+]] = apply {{%[^,]+}}([[ARG_COPY]])
  // CHECK:       [[MOVE_X:%[^,]+]] = move_value [lexical] [[X]]
  // no copy of 'x'
  _ = consumeAndProduce(x)
  // CHECK:       [[RESULT:%[^,]+]] = apply {{%[^,]+}}([[MOVE_X]])
  // CHECK:       end_borrow [[ARG_LIFETIME]]
  // release result
  // release arg
  // CHECK:       destroy_value [[RESULT]]
  // CHECK:       destroy_value [[ARG]]
  // CHECK-LABEL: } // end sil function 'eliminate_copy_of_returned_then_consumed_owned_value'
{'fraction_non_alphanumeric': 0.3653751839136832, 'fraction_numerical': 0.0029426189308484553, 'mean_word_length': 3.1453252032520327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7048817', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1074, 'n_words': 172}