Skip to content

Commit

Permalink
Fix edge case for max/min of int vs dbl
Browse files Browse the repository at this point in the history
Summary:min(x, y) should return x if x==y, but in the jit, if x and y were
ints or doubles, it returned y (this is only visible if one is an int
and the other is a double).

Reviewed By: paulbiss

Differential Revision: D3001634

fb-gh-sync-id: ce37d6e58cc12929ce793d76d73e9186f1cd1fec
shipit-source-id: ce37d6e58cc12929ce793d76d73e9186f1cd1fec
  • Loading branch information
Mark Williams authored and Hhvm Bot committed Mar 4, 2016
1 parent de69ac3 commit c1b414e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hphp/runtime/vm/jit/irgen-builtin.cpp
Expand Up @@ -404,11 +404,11 @@ SSATmp* minmax(IRGS& env, const bool is_max) {
[&] (Block* taken) {
SSATmp* cmp;
if (ty1 <= TInt && ty2 <= TInt) {
cmp = gen(env, is_max ? GteInt : LteInt, val1, val2);
cmp = gen(env, is_max ? GtInt : LtInt, val1, val2);
} else {
auto conv1 = (ty1 <= TDbl) ? val1 : gen(env, ConvIntToDbl, val1);
auto conv2 = (ty2 <= TDbl) ? val2 : gen(env, ConvIntToDbl, val2);
cmp = gen(env, is_max ? GteDbl : LteDbl, conv1, conv2);
cmp = gen(env, is_max ? GtDbl : LtDbl, conv1, conv2);
}
gen(env, JmpZero, taken, cmp);
},
Expand Down
8 changes: 8 additions & 0 deletions hphp/test/slow/arithmetic/maxmin.php
@@ -0,0 +1,8 @@
<?php

function main($a, $b) {
var_dump(min($a, $b), max($a, $b));
}

main(1.0, 1);
main(1, 1.0);
4 changes: 4 additions & 0 deletions hphp/test/slow/arithmetic/maxmin.php.expect
@@ -0,0 +1,4 @@
float(1)
float(1)
int(1)
int(1)

0 comments on commit c1b414e

Please sign in to comment.