<commit_before>; RUN: opt < %s -instsimplify -S | FileCheck %s

define i32 @negated_operand(i32 %x) {
; CHECK-LABEL: @negated_operand(
; CHECK-NEXT:    [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem i32 [[NEGX]], [[X]]
; CHECK-NEXT:    ret i32 [[REM]]
;
  %negx = sub i32 0, %x
  %rem = srem i32 %negx, %x
  ret i32 %rem
}

define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
; CHECK-LABEL: @negated_operand_commute_vec(
; CHECK-NEXT:    [[NEGX:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i32> [[NEGX]], [[X]]
; CHECK-NEXT:    ret <2 x i32> [[REM]]
;
  %negx = sub nsw <2 x i32> zeroinitializer, %x
  %rem = srem <2 x i32> %negx, %x
  ret <2 x i32> %rem
}

define i32 @knownnegation(i32 %x, i32 %y) {
; CHECK-LABEL: @knownnegation(
; CHECK-NEXT:    [[XY:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[YX:%.*]] = sub nsw i32 [[Y]], [[X]]
; CHECK-NEXT:    [[REM:%.*]] = srem i32 [[XY]], [[YX]]
; CHECK-NEXT:    ret i32 [[REM]]
;
  %xy = sub nsw i32 %x, %y
  %yx = sub nsw i32 %y, %x
  %rem = srem i32 %xy, %yx
  ret i32 %rem
}

define <2 x i32> @knownnegation_commute_vec(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @knownnegation_commute_vec(
; CHECK-NEXT:    [[XY:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[YX:%.*]] = sub nsw <2 x i32> [[Y]], [[X]]
; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i32> [[XY]], [[YX]]
; CHECK-NEXT:    ret <2 x i32> [[REM]]
;
  %xy = sub nsw <2 x i32> %x, %y
  %yx = sub nsw <2 x i32> %y, %x
  %rem = srem <2 x i32> %xy, %yx
  ret <2 x i32> %rem
}<commit_msg>[NFC][testcases] more testcases for folding srem if its two operands are negatived.<commit_after>; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s

define i32 @negated_operand(i32 %x) {
; CHECK-LABEL: @negated_operand(
; CHECK-NEXT:    [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem i32 [[NEGX]], [[X]]
; CHECK-NEXT:    ret i32 [[REM]]
;
  %negx = sub i32 0, %x
  %rem = srem i32 %negx, %x
  ret i32 %rem
}

define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
; CHECK-LABEL: @negated_operand_commute_vec(
; CHECK-NEXT:    [[NEGX:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i32> [[NEGX]], [[X]]
; CHECK-NEXT:    ret <2 x i32> [[REM]]
;
  %negx = sub nsw <2 x i32> zeroinitializer, %x
  %rem = srem <2 x i32> %negx, %x
  ret <2 x i32> %rem
}

define i32 @knownnegation(i32 %x, i32 %y) {
; CHECK-LABEL: @knownnegation(
; CHECK-NEXT:    [[XY:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[YX:%.*]] = sub nsw i32 [[Y]], [[X]]
; CHECK-NEXT:    [[REM:%.*]] = srem i32 [[XY]], [[YX]]
; CHECK-NEXT:    ret i32 [[REM]]
;
  %xy = sub nsw i32 %x, %y
  %yx = sub nsw i32 %y, %x
  %rem = srem i32 %xy, %yx
  ret i32 %rem
}

define <2 x i32> @knownnegation_commute_vec(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @knownnegation_commute_vec(
; CHECK-NEXT:    [[XY:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[YX:%.*]] = sub nsw <2 x i32> [[Y]], [[X]]
; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i32> [[XY]], [[YX]]
; CHECK-NEXT:    ret <2 x i32> [[REM]]
;
  %xy = sub nsw <2 x i32> %x, %y
  %yx = sub nsw <2 x i32> %y, %x
  %rem = srem <2 x i32> %xy, %yx
  ret <2 x i32> %rem
}

define <3 x i32> @negated_operand_vec_undef(<3 x i32> %x) {
; CHECK-LABEL: @negated_operand_vec_undef(
; CHECK-NEXT:    [[NEGX:%.*]] = sub <3 x i32> <i32 0, i32 undef, i32 0>, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem <3 x i32> [[NEGX]], [[X]]
; CHECK-NEXT:    ret <3 x i32> [[REM]]
;
  %negx = sub <3 x i32> <i32 0, i32 undef, i32 0>, %x
  %rem = srem <3 x i32> %negx, %x
  ret <3 x i32> %rem
}

define <2 x i32> @negated_operand_vec_nonsplat(<2 x i32> %x) {
; CHECK-LABEL: @negated_operand_vec_nonsplat(
; CHECK-NEXT:    [[NEGX:%.*]] = sub <2 x i32> <i32 0, i32 1>, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem <2 x i32> [[NEGX]], [[X]]
; CHECK-NEXT:    ret <2 x i32> [[REM]]
;
  %negx = sub <2 x i32> <i32 0, i32 1>, %x ; not 0, don't fold
  %rem = srem <2 x i32> %negx, %x
  ret <2 x i32> %rem
}

define i32 @negated_operand_commute(i32 %x) {
; CHECK-LABEL: @negated_operand_commute(
; CHECK-NEXT:    [[NEGX:%.*]] = sub i32 0, [[X:%.*]]
; CHECK-NEXT:    [[REM:%.*]] = srem i32 [[X]], [[NEGX]]
; CHECK-NEXT:    ret i32 [[REM]]
;
  %negx = sub i32 0, %x
  %rem = srem i32 %x, %negx
  ret i32 %rem
}
{'fraction_non_alphanumeric': 0.24311001568451715, 'fraction_numerical': 0.06475464933900964, 'mean_word_length': 3.255481410867493, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4722754', 'n_tokens_mistral': 2163, 'n_tokens_neox': 2079, 'n_words': 619}