Fix min/max signed zero and NaN handling.

Make min(x, y) equal to (x < y ? x : y) and max(x, y) equal to
(x > y ? x : y), including the behavior for signed zeros and NaNs.
This also enables optimizing them into min and max SSE2 instructions
on x86.

Bug swiftshader:19

Change-Id: I047b90e9da9f3c72657ab7c619bc91b92a700a45
Reviewed-on: https://swiftshader-review.googlesource.com/8771
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index e5208cf..30f4714 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -6040,11 +6040,11 @@
 	RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
 	{
 		Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
-		auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value);
+		auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ogt, condition, x.value, y.value);
 		::basicBlock->appendInst(cmp);
 
 		Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
-		auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+		auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
 		::basicBlock->appendInst(select);
 
 		return RValue<Float4>(V(result));
@@ -6053,11 +6053,11 @@
 	RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
 	{
 		Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
-		auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value);
+		auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Olt, condition, x.value, y.value);
 		::basicBlock->appendInst(cmp);
 
 		Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
-		auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
+		auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
 		::basicBlock->appendInst(select);
 
 		return RValue<Float4>(V(result));