I think it is better to use _mm256_cmp_ps for your question. For this purpose I completed the following program. This is more than you want. If you want to save them, you must set all mask elements to 1 , but if you want to save a different number, you can change the value of the mask to whatever you want.
The output for mask = {1,1,1,1,1,1,1,1} :
vec1 : [0]=1.20, [1]=0.50, [2]=1.70, [3]=1.90, [4]=0.34, [5]=22.90, [6]=18.60, [7]=1.00 vec2 : [0]=-nan, [1]=0.00, [2]=-nan, [3]=-nan, [4]=0.00, [5]=-nan, [6]=-nan, [7]=0.00 vec3 : [0]=1.00, [1]=0.00, [2]=1.00, [3]=1.00, [4]=0.00, [5]=1.00, [6]=1.00, [7]=0.00
And for mask = {2,2,2,2,2,2,2,2} :
vec1 : [0]=1.20, [1]=0.50, [2]=1.70, [3]=1.90, [4]=0.34, [5]=22.90, [6]=18.60, [7]=1.00 vec2 : [0]=0.00, [1]=0.00, [2]=0.00, [3]=0.00, [4]=0.00, [5]=-nan, [6]=-nan, [7]=0.00 vec3 : [0]=0.00, [1]=0.00, [2]=0.00, [3]=0.00, [4]=0.00, [5]=2.00, [6]=2.00, [7]=0.00
It depends on the non-commutative behavior of _mm256_min_ps with NaN to replace NaN elements with 1.0. NaN > 1.0 : NaN : 1.0 = 1.0 , because NaN > anything always false.
Beware that gcc before 7.0 treats the built-in 128b _mm_min_ps as commutative, even without -ffast-math (although it knows that the minps instruction minps not), use the latest version of gcc or make sure gcc chooses to compile your code using operands in order, necessary for this algorithm. (Or use clang). It is possible that gcc will never replace operands with AVX, only with SSE (to avoid additional movapd instructions), but the safest thing is to use gcc7 or later.