Discussion:
vex: r3304 - in /trunk/priv: host_mips_defs.c host_mips_isel.c
(too old to reply)
s***@valgrind.org
2017-02-13 16:15:25 UTC
Permalink
Raw Message
Author: petarj
Date: Mon Feb 13 16:15:24 2017
New Revision: 3304

Log:
mips64: do correct 32-bit comparison for Iop_CmpNE32

Make sure that we take into account 32-bit size of values in comparison
on MIPS64-platforms. This is done either by sign extending these values
before comparison or sign extending xored values (depending on what
comparison we do). This should avoid false-positives like the one
reported in BZ #341481.

Patch based on code provided by Crestez Dan Leonard and Tamara Vlahovic.

Modified:
trunk/priv/host_mips_defs.c
trunk/priv/host_mips_isel.c

Modified: trunk/priv/host_mips_defs.c
==============================================================================
--- trunk/priv/host_mips_defs.c (original)
+++ trunk/priv/host_mips_defs.c Mon Feb 13 16:15:24 2017
@@ -1584,8 +1584,15 @@
addHRegUse(u, HRmWrite, i->Min.Shft.dst);
return;
case Min_Cmp:
- addHRegUse(u, HRmRead, i->Min.Cmp.srcL);
- addHRegUse(u, HRmRead, i->Min.Cmp.srcR);
+ if (i->Min.Cmp.sz32 && mode64 &&
+ (i->Min.Cmp.cond != MIPScc_EQ) &&
+ (i->Min.Cmp.cond != MIPScc_NE)) {
+ addHRegUse(u, HRmModify, i->Min.Cmp.srcL);
+ addHRegUse(u, HRmModify, i->Min.Cmp.srcR);
+ } else {
+ addHRegUse(u, HRmRead, i->Min.Cmp.srcL);
+ addHRegUse(u, HRmRead, i->Min.Cmp.srcR);
+ }
addHRegUse(u, HRmWrite, i->Min.Cmp.dst);
return;
case Min_Unary:
@@ -2754,35 +2761,68 @@
UInt r_srcL = iregNo(i->Min.Cmp.srcL, mode64);
UInt r_srcR = iregNo(i->Min.Cmp.srcR, mode64);
UInt r_dst = iregNo(i->Min.Cmp.dst, mode64);
+ Bool sz32 = i->Min.Cmp.sz32;

switch (i->Min.Cmp.cond) {
case MIPScc_EQ:
/* xor r_dst, r_srcL, r_srcR
sltiu r_dst, r_dst, 1 */
p = mkFormR(p, 0, r_srcL, r_srcR, r_dst, 0, 38);
+ if (mode64 && sz32) {
+ /* sll r_dst, r_dst, 0 */
+ p = mkFormS(p, 0, r_dst, 0, r_dst, 0, 0);
+ }
p = mkFormI(p, 11, r_dst, r_dst, 1);
break;
case MIPScc_NE:
/* xor r_dst, r_srcL, r_srcR
sltu r_dst, zero, r_dst */
p = mkFormR(p, 0, r_srcL, r_srcR, r_dst, 0, 38);
+ if (mode64 && sz32) {
+ /* sll r_dst, r_dst, 0 */
+ p = mkFormS(p, 0, r_dst, 0, r_dst, 0, 0);
+ }
p = mkFormR(p, 0, 0, r_dst, r_dst, 0, 43);
break;
case MIPScc_LT:
+ if (mode64 && sz32) {
+ /* sll r_srcL, r_srcL, 0
+ sll r_srcR, r_srcR, 0 */
+ p = mkFormS(p, 0, r_srcL, 0, r_srcL, 0, 0);
+ p = mkFormS(p, 0, r_srcR, 0, r_srcR, 0, 0);
+ }
/* slt r_dst, r_srcL, r_srcR */
p = mkFormR(p, 0, r_srcL, r_srcR, r_dst, 0, 42);
break;
case MIPScc_LO:
+ if (mode64 && sz32) {
+ /* sll r_srcL, r_srcL, 0
+ sll r_srcR, r_srcR, 0 */
+ p = mkFormS(p, 0, r_srcL, 0, r_srcL, 0, 0);
+ p = mkFormS(p, 0, r_srcR, 0, r_srcR, 0, 0);
+ }
/* sltu r_dst, r_srcL, r_srcR */
p = mkFormR(p, 0, r_srcL, r_srcR, r_dst, 0, 43);
break;
case MIPScc_LE:
+ if (mode64 && sz32) {
+ /* sll r_srcL, r_srcL, 0
+ sll r_srcR, r_srcR, 0 */
+ p = mkFormS(p, 0, r_srcL, 0, r_srcL, 0, 0);
+ p = mkFormS(p, 0, r_srcR, 0, r_srcR, 0, 0);
+ }
/* slt r_dst, r_srcR, r_srcL
xori r_dst, r_dst, 1 */
p = mkFormR(p, 0, r_srcR, r_srcL, r_dst, 0, 42);
p = mkFormI(p, 14, r_dst, r_dst, 1);
break;
case MIPScc_LS:
+ if (mode64 && sz32) {
+ /* sll r_srcL, r_srcL, 0
+ sll r_srcR, r_srcR, 0 */
+ p = mkFormS(p, 0, r_srcL, 0, r_srcL, 0, 0);
+ p = mkFormS(p, 0, r_srcR, 0, r_srcR, 0, 0);
+ }
/* sltu r_dst, rsrcR, r_srcL
xori r_dsr, r_dst, 1 */
p = mkFormR(p, 0, r_srcR, r_srcL, r_dst, 0, 43);

Modified: trunk/priv/host_mips_isel.c
==============================================================================
--- trunk/priv/host_mips_isel.c (original)
+++ trunk/priv/host_mips_isel.c Mon Feb 13 16:15:24 2017
@@ -1000,7 +1000,7 @@
break;
case Iop_CmpNE64:
cc = MIPScc_NE;
- size32 = True;
+ size32 = False;
break;
case Iop_CmpLT32S:
cc = MIPScc_LT;
@@ -2080,7 +2080,7 @@
break;
case Iop_CmpNE64:
cc = MIPScc_NE;
- size32 = True;
+ size32 = False;
break;
case Iop_CmpLT32S:
cc = MIPScc_LT;

Loading...