⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 265891 in webkit


Ignore:
Timestamp:
Aug 19, 2020, 12:46:35 PM (6 years ago)
Author:
Tadeu Zagallo
Message:

B3 IntRange is incorrect for negative masks
https://bugs.webkit.org/show_bug.cgi?id=215536
<rdar://problem/67130430>

Reviewed by Michael Saboff and Robin Morisset.

In the B3 ReduceStrength phase, we compute rangeForMask as (0, mask). This is correct for
positive values, but incorrect when negative. To fix it, we use (INT_MIN & mask, INT_MAX & mask)
as the range for negative masks.

  • b3/B3ReduceStrength.cpp:
  • b3/testb3.h:
  • b3/testb3_1.cpp:

(run):

  • b3/testb3_5.cpp:

(testCheckSubBitAnd):

Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r265830 r265891  
     12020-08-19  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        B3 IntRange is incorrect for negative masks
     4        https://bugs.webkit.org/show_bug.cgi?id=215536
     5        <rdar://problem/67130430>
     6
     7        Reviewed by Michael Saboff and Robin Morisset.
     8
     9        In the B3 ReduceStrength phase, we compute rangeForMask as (0, mask).  This is correct for
     10        positive values, but incorrect when negative. To fix it, we use `(INT_MIN & mask, INT_MAX & mask)`
     11        as the range for negative masks.
     12
     13        * b3/B3ReduceStrength.cpp:
     14        * b3/testb3.h:
     15        * b3/testb3_1.cpp:
     16        (run):
     17        * b3/testb3_5.cpp:
     18        (testCheckSubBitAnd):
     19
    1202020-08-18  Saam Barati  <sbarati@apple.com>
    221
  • trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp

    r261755 r265891  
    124124        if (!(mask + 1))
    125125            return top<T>();
     126        if (mask < 0)
     127            return IntRange(INT_MIN & mask, mask & INT_MAX);
    126128        return IntRange(0, mask);
    127129    }
  • trunk/Source/JavaScriptCore/b3/testb3.h

    r254832 r265891  
    805805void testCheckSubBadImm();
    806806void testCheckSub();
     807void testCheckSubBitAnd();
    807808double doubleSub(double, double);
    808809void testCheckSub64();
  • trunk/Source/JavaScriptCore/b3/testb3_1.cpp

    r263635 r265891  
    497497    RUN(testCheckSubBadImm());
    498498    RUN(testCheckSub());
     499    RUN(testCheckSubBitAnd());
    499500    RUN(testCheckSub64());
    500501    RUN(testCheckSubFold(100, 200));
  • trunk/Source/JavaScriptCore/b3/testb3_5.cpp

    r259786 r265891  
    11241124    CHECK(invoke<double>(*code, 42, 42) == 0.0);
    11251125    CHECK(invoke<double>(*code, -2147483647, 42) == -2147483689.0);
     1126}
     1127
     1128void testCheckSubBitAnd()
     1129{
     1130    Procedure proc;
     1131    if (proc.optLevel() < 1)
     1132        return;
     1133    BasicBlock* root = proc.addBlock();
     1134    Value* zero = root->appendNew<Const32Value>(proc, Origin(), 0);
     1135    Value* arg1 = root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0);
     1136    Value* truncatedArg1 = root->appendNew<Value>(proc, Trunc, Origin(), arg1);
     1137    Value* minusTwo = root->appendNew<Const32Value>(proc, Origin(), -2);
     1138    Value* bitAnd = root->appendNew<Value>(proc, BitAnd, Origin(), truncatedArg1, minusTwo);
     1139    CheckValue* checkSub = root->appendNew<CheckValue>(proc, CheckSub, Origin(), zero, bitAnd);
     1140    checkSub->setGenerator([&] (CCallHelpers& jit, const StackmapGenerationParams&) {
     1141        AllowMacroScratchRegisterUsage allowScratch(jit);
     1142        jit.move(CCallHelpers::TrustedImm32(42), GPRInfo::returnValueGPR);
     1143        jit.emitFunctionEpilogue();
     1144        jit.ret();
     1145    });
     1146    root->appendNewControlValue(proc, Return, Origin(), checkSub);
     1147
     1148    auto code = compileProc(proc);
     1149
     1150    CHECK_EQ(invoke<int>(*code, 1), 0);
     1151    CHECK_EQ(invoke<int>(*code, 2), -2);
     1152    CHECK_EQ(invoke<int>(*code, 3), -2);
     1153    CHECK_EQ(invoke<int>(*code, -1), 2);
     1154    CHECK_EQ(invoke<int>(*code, -2), 2);
     1155    CHECK_EQ(invoke<int>(*code, -3), 4);
     1156    CHECK_EQ(invoke<int>(*code, INT_MAX), -(INT_MAX - 1));
     1157    CHECK_EQ(invoke<int>(*code, INT_MIN), 42);
    11261158}
    11271159
Note: See TracChangeset for help on using the changeset viewer.