1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instsimplify -S | FileCheck %s 3 4; Default NaN constant 5 6define double @fadd_nan_op0(double %x) { 7; CHECK-LABEL: @fadd_nan_op0( 8; CHECK-NEXT: ret double 0x7FF8000000000000 9; 10 %r = fadd double 0x7FF8000000000000, %x 11 ret double %r 12} 13 14; Sign bit is set 15 16define double @fadd_nan_op1(double %x) { 17; CHECK-LABEL: @fadd_nan_op1( 18; CHECK-NEXT: ret double 0xFFF8000000000000 19; 20 %r = fadd double %x, 0xFFF8000000000000 21 ret double %r 22} 23 24; Non-zero payload 25 26define float @fsub_nan_op0(float %x) { 27; CHECK-LABEL: @fsub_nan_op0( 28; CHECK-NEXT: ret float 0x7FFFFF0000000000 29; 30 %r = fsub float 0x7FFFFF0000000000, %x 31 ret float %r 32} 33 34; Signaling 35 36define float @fsub_nan_op1(float %x) { 37; CHECK-LABEL: @fsub_nan_op1( 38; CHECK-NEXT: ret float 0x7FF1000000000000 39; 40 %r = fsub float %x, 0x7FF1000000000000 41 ret float %r 42} 43 44; Signaling and signed 45 46define double @fmul_nan_op0(double %x) { 47; CHECK-LABEL: @fmul_nan_op0( 48; CHECK-NEXT: ret double 0xFFF0000000000001 49; 50 %r = fmul double 0xFFF0000000000001, %x 51 ret double %r 52} 53 54; Vector type 55 56define <2 x float> @fmul_nan_op1(<2 x float> %x) { 57; CHECK-LABEL: @fmul_nan_op1( 58; CHECK-NEXT: ret <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000> 59; 60 %r = fmul <2 x float> %x, <float 0x7FF8000000000000, float 0x7FF8000000000000> 61 ret <2 x float> %r 62} 63 64; Vector signed and non-zero payload 65 66define <2 x double> @fdiv_nan_op0(<2 x double> %x) { 67; CHECK-LABEL: @fdiv_nan_op0( 68; CHECK-NEXT: ret <2 x double> <double 0xFFF800000000000F, double 0xFFF800000000000F> 69; 70 %r = fdiv <2 x double> <double 0xFFF800000000000F, double 0xFFF800000000000F>, %x 71 ret <2 x double> %r 72} 73 74; Vector with different NaN constant elements 75 76define <2 x half> @fdiv_nan_op1(<2 x half> %x) { 77; CHECK-LABEL: @fdiv_nan_op1( 78; CHECK-NEXT: ret <2 x half> <half 0xH7FFF, half 0xHFF00> 79; 80 %r = fdiv <2 x half> %x, <half 0xH7FFF, half 0xHFF00> 81 ret <2 x half> %r 82} 83 84; Vector with undef element 85 86define <2 x double> @frem_nan_op0(<2 x double> %x) { 87; CHECK-LABEL: @frem_nan_op0( 88; CHECK-NEXT: ret <2 x double> <double 0x7FF8000000000000, double 0x7FF8000000000000> 89; 90 %r = frem <2 x double> <double 0xFFFF000000000000, double undef>, %x 91 ret <2 x double> %r 92} 93 94define float @frem_nan_op1(float %x) { 95; CHECK-LABEL: @frem_nan_op1( 96; CHECK-NEXT: ret float 0x7FF8000000000000 97; 98 %r = frem float %x, 0x7FF8000000000000 99 ret float %r 100} 101 102; Special-case: fneg must only change the sign bit (this is handled by constant folding). 103 104define double @fneg_nan_1(double %x) { 105; CHECK-LABEL: @fneg_nan_1( 106; CHECK-NEXT: ret double 0x7FFABCDEF0123456 107; 108 %r = fsub double -0.0, 0x7FFABCDEF0123456 109 ret double %r 110} 111 112define double @unary_fneg_nan_1(double %x) { 113; CHECK-LABEL: @unary_fneg_nan_1( 114; CHECK-NEXT: ret double 0xFFFABCDEF0123456 115; 116 %r = fneg double 0x7FFABCDEF0123456 117 ret double %r 118} 119 120define <2 x double> @fneg_nan_2(<2 x double> %x) { 121; CHECK-LABEL: @fneg_nan_2( 122; CHECK-NEXT: ret <2 x double> <double 0xFFF9234567890ABC, double 0x7FF8000000000001> 123; 124 %r = fsub <2 x double> <double -0.0, double -0.0>, <double 0xFFF1234567890ABC, double 0x7FF0000000000001> 125 ret <2 x double> %r 126} 127 128define <2 x double> @unary_fneg_nan_2(<2 x double> %x) { 129; CHECK-LABEL: @unary_fneg_nan_2( 130; CHECK-NEXT: ret <2 x double> <double 0x7FF1234567890ABC, double 0xFFF0000000000001> 131; 132 %r = fneg <2 x double> <double 0xFFF1234567890ABC, double 0x7FF0000000000001> 133 ret <2 x double> %r 134} 135 136; Repeat all tests with fast-math-flags. Alternate 'nnan' and 'fast' for more coverage. 137 138define float @fadd_nan_op0_nnan(float %x) { 139; CHECK-LABEL: @fadd_nan_op0_nnan( 140; CHECK-NEXT: ret float undef 141; 142 %r = fadd nnan float 0x7FF8000000000000, %x 143 ret float %r 144} 145 146define float @fadd_nan_op1_fast(float %x) { 147; CHECK-LABEL: @fadd_nan_op1_fast( 148; CHECK-NEXT: ret float undef 149; 150 %r = fadd fast float %x, 0x7FF8000000000000 151 ret float %r 152} 153 154define float @fsub_nan_op0_fast(float %x) { 155; CHECK-LABEL: @fsub_nan_op0_fast( 156; CHECK-NEXT: ret float undef 157; 158 %r = fsub fast float 0x7FF8000000000000, %x 159 ret float %r 160} 161 162define float @fsub_nan_op1_nnan(float %x) { 163; CHECK-LABEL: @fsub_nan_op1_nnan( 164; CHECK-NEXT: ret float undef 165; 166 %r = fsub nnan float %x, 0x7FF8000000000000 167 ret float %r 168} 169 170define float @fmul_nan_op0_nnan(float %x) { 171; CHECK-LABEL: @fmul_nan_op0_nnan( 172; CHECK-NEXT: ret float undef 173; 174 %r = fmul nnan float 0x7FF8000000000000, %x 175 ret float %r 176} 177 178define float @fmul_nan_op1_fast(float %x) { 179; CHECK-LABEL: @fmul_nan_op1_fast( 180; CHECK-NEXT: ret float undef 181; 182 %r = fmul fast float %x, 0x7FF8000000000000 183 ret float %r 184} 185 186define float @fdiv_nan_op0_fast(float %x) { 187; CHECK-LABEL: @fdiv_nan_op0_fast( 188; CHECK-NEXT: ret float undef 189; 190 %r = fdiv fast float 0x7FF8000000000000, %x 191 ret float %r 192} 193 194define float @fdiv_nan_op1_nnan(float %x) { 195; CHECK-LABEL: @fdiv_nan_op1_nnan( 196; CHECK-NEXT: ret float undef 197; 198 %r = fdiv nnan float %x, 0x7FF8000000000000 199 ret float %r 200} 201 202define float @frem_nan_op0_nnan(float %x) { 203; CHECK-LABEL: @frem_nan_op0_nnan( 204; CHECK-NEXT: ret float undef 205; 206 %r = frem nnan float 0x7FF8000000000000, %x 207 ret float %r 208} 209 210define float @frem_nan_op1_fast(float %x) { 211; CHECK-LABEL: @frem_nan_op1_fast( 212; CHECK-NEXT: ret float undef 213; 214 %r = frem fast float %x, 0x7FF8000000000000 215 ret float %r 216} 217 218