<commit_before>; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s

define float @fadd_nan_op0(float %x) {
; CHECK-LABEL: @fadd_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fadd float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fadd float 0x7FF8000000000000, %x
  ret float %r
}

define float @fadd_nan_op1(float %x) {
; CHECK-LABEL: @fadd_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fadd float [[X:%.*]], 0x7FF8000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = fadd float %x, 0x7FF8000000000000
  ret float %r
}

define float @fsub_nan_op0(float %x) {
; CHECK-LABEL: @fsub_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fsub float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fsub float 0x7FF8000000000000, %x
  ret float %r
}

define float @fsub_nan_op1(float %x) {
; CHECK-LABEL: @fsub_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fsub float [[X:%.*]], 0x7FF8000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = fsub float %x, 0x7FF8000000000000
  ret float %r
}

define float @fmul_nan_op0(float %x) {
; CHECK-LABEL: @fmul_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fmul float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fmul float 0x7FF8000000000000, %x
  ret float %r
}

define float @fmul_nan_op1(float %x) {
; CHECK-LABEL: @fmul_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fmul float [[X:%.*]], 0x7FF8000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = fmul float %x, 0x7FF8000000000000
  ret float %r
}

define float @fdiv_nan_op0(float %x) {
; CHECK-LABEL: @fdiv_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fdiv float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fdiv float 0x7FF8000000000000, %x
  ret float %r
}

define float @fdiv_nan_op1(float %x) {
; CHECK-LABEL: @fdiv_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fdiv float [[X:%.*]], 0x7FF8000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = fdiv float %x, 0x7FF8000000000000
  ret float %r
}

define float @frem_nan_op0(float %x) {
; CHECK-LABEL: @frem_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = frem float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = frem float 0x7FF8000000000000, %x
  ret float %r
}

define float @frem_nan_op1(float %x) {
; CHECK-LABEL: @frem_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = frem float [[X:%.*]], 0x7FF8000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = frem float %x, 0x7FF8000000000000
  ret float %r
}

; Repeat all tests with fast-math-flags. Alternate 'nnan' and 'fast' for more coverage.

define float @fadd_nan_op0_nnan(float %x) {
; CHECK-LABEL: @fadd_nan_op0_nnan(
; CHECK-NEXT:    [[R:%.*]] = fadd nnan float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fadd nnan float 0x7FF8000000000000, %x
  ret float %r<commit_msg>[InstSimplify] add NaN constant diversity; NFC<commit_after>; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s

; Default NaN constant

define double @fadd_nan_op0(double %x) {
; CHECK-LABEL: @fadd_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fadd double 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret double [[R]]
;
  %r = fadd double 0x7FF8000000000000, %x
  ret double %r
}

; Sign bit is set

define double @fadd_nan_op1(double %x) {
; CHECK-LABEL: @fadd_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fadd double [[X:%.*]], 0xFFF8000000000000
; CHECK-NEXT:    ret double [[R]]
;
  %r = fadd double %x, 0xFFF8000000000000
  ret double %r
}

; Non-zero payload

define float @fsub_nan_op0(float %x) {
; CHECK-LABEL: @fsub_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fsub float 0x7FFFFF0000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fsub float 0x7FFFFF0000000000, %x
  ret float %r
}

; Signaling

define float @fsub_nan_op1(float %x) {
; CHECK-LABEL: @fsub_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fsub float [[X:%.*]], 0x7FF1000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = fsub float %x, 0x7FF1000000000000
  ret float %r
}

; Signaling and signed

define double @fmul_nan_op0(double %x) {
; CHECK-LABEL: @fmul_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fmul double 0xFFF0000000000001, [[X:%.*]]
; CHECK-NEXT:    ret double [[R]]
;
  %r = fmul double 0xFFF0000000000001, %x
  ret double %r
}

; Vector type

define <2 x float> @fmul_nan_op1(<2 x float> %x) {
; CHECK-LABEL: @fmul_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fmul <2 x float> [[X:%.*]], <float 0x7FF8000000000000, float 0x7FF8000000000000>
; CHECK-NEXT:    ret <2 x float> [[R]]
;
  %r = fmul <2 x float> %x, <float 0x7FF8000000000000, float 0x7FF8000000000000>
  ret <2 x float> %r
}

; Vector signed and non-zero payload

define <2 x double> @fdiv_nan_op0(<2 x double> %x) {
; CHECK-LABEL: @fdiv_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = fdiv <2 x double> <double 0xFFF800000000000F, double 0xFFF800000000000F>, [[X:%.*]]
; CHECK-NEXT:    ret <2 x double> [[R]]
;
  %r = fdiv <2 x double> <double 0xFFF800000000000F, double 0xFFF800000000000F>, %x
  ret <2 x double>  %r
}

; Vector with different NaN constant elements

define <2 x half> @fdiv_nan_op1(<2 x half> %x) {
; CHECK-LABEL: @fdiv_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = fdiv <2 x half> [[X:%.*]], <half 0xH7FFF, half 0xHFF00>
; CHECK-NEXT:    ret <2 x half> [[R]]
;
  %r = fdiv <2 x half> %x, <half 0xH7FFF, half 0xHFF00>
  ret <2 x half> %r
}

; Vector with undef element

define <2 x double> @frem_nan_op0(<2 x double> %x) {
; CHECK-LABEL: @frem_nan_op0(
; CHECK-NEXT:    [[R:%.*]] = frem <2 x double> <double 0xFFFF000000000000, double undef>, [[X:%.*]]
; CHECK-NEXT:    ret <2 x double> [[R]]
;
  %r = frem <2 x double> <double 0xFFFF000000000000, double undef>, %x
  ret <2 x double> %r
}

define float @frem_nan_op1(float %x) {
; CHECK-LABEL: @frem_nan_op1(
; CHECK-NEXT:    [[R:%.*]] = frem float [[X:%.*]], 0x7FF8000000000000
; CHECK-NEXT:    ret float [[R]]
;
  %r = frem float %x, 0x7FF8000000000000
  ret float %r
}

; Special-case: fneg must only change the sign bit (this is handled by constant folding).

define double @fneg_nan_1(double %x) {
; CHECK-LABEL: @fneg_nan_1(
; CHECK-NEXT:    ret double 0xFFFABCDEF0123456
;
  %r = fsub double -0.0, 0x7FFABCDEF0123456
  ret double %r
}

define <2 x double> @fneg_nan_2(<2 x double> %x) {
; CHECK-LABEL: @fneg_nan_2(
; CHECK-NEXT:    ret <2 x double> <double 0x7FF1234567890ABC, double 0xFFF0000000000001>
;
  %r = fsub <2 x double> <double -0.0, double -0.0>, <double 0xFFF1234567890ABC, double 0x7FF0000000000001>
  ret <2 x double> %r
}

; Repeat all tests with fast-math-flags. Alternate 'nnan' and 'fast' for more coverage.

define float @fadd_nan_op0_nnan(float %x) {
; CHECK-LABEL: @fadd_nan_op0_nnan(
; CHECK-NEXT:    [[R:%.*]] = fadd nnan float 0x7FF8000000000000, [[X:%.*]]
; CHECK-NEXT:    ret float [[R]]
;
  %r = fadd nnan float 0x7FF8000000000000, %x
  ret float %r
{'fraction_non_alphanumeric': 0.17397020157756354, 'fraction_numerical': 0.12123867952088811, 'mean_word_length': 3.9760174418604652, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 48, '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': '7645035', 'n_tokens_mistral': 3362, 'n_tokens_neox': 2873, 'n_words': 761}