Skip to content

Commit

Permalink
C++: Fix join order problem after stats file update
Browse files Browse the repository at this point in the history
Tuple counts before the change (terminated early):
```
[2025-01-11 17:49:42] (297s) Tuple counts for AliasedSSA::getResultMemoryLocation/1#eb4efd2d/2@c513392o after 13.5s:
                      0          ~0%       {3} r1 = JOIN `_SSAConstruction::getInstructionOpcode/2#ec2d1f97_10#join_rhs__AliasedSSA::canReuseSsaForOldResult/1__#shared` WITH Opcode::MayWriteOpcode#class#21b7b7f2 ON FIRST 1 OUTPUT Lhs.1, Lhs.2 'instr', _
                      0          ~0%       {3}    | REWRITE WITH Out.2 := true

                      30500      ~124%     {2} r2 = SCAN `_AliasedSSA::canReuseSsaForOldResult/1#280fbda5_Opcode::Opcode.getWriteMemoryAccess/0#dispred#531702__#shared` OUTPUT In.1, In.0 'instr'
                                           {2}    | AND NOT `_Opcode::MayWriteOpcode#class#21b7b7f2__SSAConstruction::getInstructionOpcode/2#ec2d1f97_10#join_rhs__#antijoin_rhs#1`(FIRST 2)
                      30500      ~134%     {3}    | SCAN OUTPUT In.0, In.1 'instr', _
                      30500      ~120%     {3}    | REWRITE WITH Out.2 := false

                      30500      ~120%     {3} r3 = r1 UNION r2

                      8000       ~738%     {2} r4 = JOIN r3 WITH num#MemoryAccessKind::TEscapedMemoryAccess#a0368c86 ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                                           {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)
                      4000       ~699%     {2}    | SCAN OUTPUT In.1, In.0 'instr'
                      1501792000 ~686%     {3}    | JOIN WITH num#AliasedSSA::TAllAliasedMemory#4bb632db_102#join_rhs ON FIRST 1 OUTPUT Rhs.2 'result', Lhs.1 'instr', Rhs.1
                      1501788000 ~709%     {3}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2, Lhs.0 'result'
                      0          ~0%       {2}    | JOIN WITH `SSAConstruction::getInstructionEnclosingIRFunction/1#d26c0476` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.2 'result'

                      8000       ~674%     {2} r5 = JOIN r3 WITH num#MemoryAccessKind::TNonLocalMemoryAccess#b2a59f45 ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                                           {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)
                      4000       ~689%     {2}    | SCAN OUTPUT In.1, In.0 'instr'
                      310509500  ~547%     {3}    | JOIN WITH num#AliasedSSA::TAllNonLocalMemory#7ba9f6c9_102#join_rhs ON FIRST 1 OUTPUT Rhs.2 'result', Lhs.1 'instr', Rhs.1
                      310504500  ~527%     {3}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2, Lhs.0 'result'
                      0          ~0%       {2}    | JOIN WITH `SSAConstruction::getInstructionEnclosingIRFunction/1#d26c0476` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.2 'result'

                      5000       ~2%       {2} r6 = JOIN r3 WITH `AliasedSSA::isIndirectOrBufferMemoryAccess/1#a6492554` ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                      5000       ~2%       {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)

                                           {2} r7 = r6 AND NOT `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#7`(FIRST 1)
                      0          ~0%       {2}    | SCAN OUTPUT In.1, In.0 'instr'
                      0          ~0%       {3}    | JOIN WITH num#AliasedSSA::TUnknownMemoryLocation#e0c2a990_102#join_rhs ON FIRST 1 OUTPUT Rhs.2 'result', Lhs.1 'instr', Rhs.1
                      0          ~0%       {3}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2, Lhs.0 'result'
                      0          ~0%       {2}    | JOIN WITH `SSAConstruction::getInstructionEnclosingIRFunction/1#d26c0476` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.2 'result'

                      5000       ~0%       {2} r8 = JOIN r3 WITH num#MemoryAccessKind::TEntireAllocationMemoryAccess#503d0afb ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                      5000       ~0%       {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)
                      4500       ~2%       {4}    | JOIN WITH `Instruction::Instruction.getResultAddressOperand/0#dispred#619d4407` ON FIRST 1 OUTPUT Rhs.1, Lhs.0 'instr', _, Lhs.1
                      4500       ~4%       {3}    | REWRITE WITH Out.2 := booleanNot(In.3) KEEPING 3
                      0          ~0%       {3}    | JOIN WITH `project#AliasAnalysis::addressOperandAllocationAndOffset/3#c64a9862` ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'instr', Lhs.2
                      0          ~0%       {4}    | JOIN WITH num#AliasedSSA::TEntireAllocationMemoryLocation#85bb24dd ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2, Rhs.1, Rhs.2 'result'
                                           {4}    | REWRITE WITH TEST InOut.1 != InOut.2
                      0          ~0%       {2}    | SCAN OUTPUT In.3 'result', In.0 'instr'
                      0          ~0%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      4500       ~0%       {5} r9 = JOIN r6 WITH `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#5_0512346#join_rhs` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.1, Rhs.2, Rhs.6, _
                                           {4}    | REWRITE WITH Tmp.4 := false, TEST InOut.3 != Tmp.4 KEEPING 4
                      0          ~0%       {5}    | SCAN OUTPUT In.2, _, In.0 'instr', _, In.1
                      0          ~0%       {4}    | REWRITE WITH Out.1 := false, Out.3 := booleanNot(In.4) KEEPING 4
                      0          ~0%       {4}    | JOIN WITH `AliasedSSA::getGroupedMemoryLocation/3#14ef79fc#ffbf_0213#join_rhs` ON FIRST 2 OUTPUT Lhs.2 'instr', Lhs.3, Rhs.2, Rhs.3 'result'
                                           {4}    | REWRITE WITH TEST InOut.1 != InOut.2
                      0          ~0%       {2}    | SCAN OUTPUT In.3 'result', In.0 'instr'
                      0          ~0%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      4500       ~0%       {8} r10 = JOIN r6 WITH `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#5_0512346#join_rhs` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.1, Rhs.2, Rhs.3, Rhs.4, Rhs.5, Rhs.6, _
                                           {7}    | REWRITE WITH Tmp.7 := false, TEST InOut.6 = Tmp.7 KEEPING 7
                      4000       ~0%       {6}    | SCAN OUTPUT In.2, In.3, In.4, In.5, In.0 'instr', In.1
                      3500       ~1%       {8}    | JOIN WITH num#AliasedSSA::TVariableMemoryLocation#8e8cb20c_013456#join_rhs ON FIRST 4 OUTPUT Rhs.5 'result', Lhs.4 'instr', Lhs.5, Lhs.0, Lhs.1, Lhs.2, Lhs.3, Rhs.4
                      3000       ~0%       {8}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.3, Lhs.4, Lhs.5, Lhs.6, Lhs.2, Lhs.7, Lhs.0 'result'
                      2500       ~2%       {5}    | JOIN WITH `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#6` ON FIRST 6 OUTPUT Lhs.0 'instr', Lhs.6, Lhs.7 'result', _, Lhs.5
                                           {4}    | REWRITE WITH Out.3 := booleanNot(In.4), TEST Out.3 != InOut.1 KEEPING 4
                      2000       ~0%       {2}    | SCAN OUTPUT In.0 'instr', In.2 'result'

                      2000       ~0%       {2} r11 = r4 UNION r5 UNION r7 UNION r8 UNION r9 UNION r10
                                           return r11
```

Tuple counts after:
```
[2025-01-11 17:52:46] (9s) Tuple counts for AliasedSSA::getResultMemoryLocation/1#eb4efd2d/2@6c9e69ae after 6.1s:
                      1283623 ~5%       {3} r1 = JOIN `_SSAConstruction::getInstructionOpcode/2#ec2d1f97_10#join_rhs__AliasedSSA::canReuseSsaForOldResult/1__#shared` WITH Opcode::MayWriteOpcode#class#21b7b7f2 ON FIRST 1 OUTPUT Lhs.1, Lhs.2 'instr', _
                      1283623 ~0%       {3}    | REWRITE WITH Out.2 := true

                      2965447 ~0%       {2} r2 = SCAN `_AliasedSSA::canReuseSsaForOldResult/1#280fbda5_Opcode::Opcode.getWriteMemoryAccess/0#dispred#531702__#shared` OUTPUT In.1, In.0 'instr'
                                        {2}    | AND NOT `_Opcode::MayWriteOpcode#class#21b7b7f2__SSAConstruction::getInstructionOpcode/2#ec2d1f97_10#join_rhs__#antijoin_rhs#1`(FIRST 2)
                      1681824 ~1%       {3}    | SCAN OUTPUT In.0, In.1 'instr', _
                      1681824 ~0%       {3}    | REWRITE WITH Out.2 := false

                      2965447 ~0%       {3} r3 = r1 UNION r2

                      1334818 ~0%       {2} r4 = JOIN r3 WITH num#MemoryAccessKind::TEscapedMemoryAccess#a0368c86 ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                      1334818 ~0%       {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)
                      1334818 ~6%       {3}    | JOIN WITH `SSAConstruction::getInstructionEnclosingIRFunction/1#d26c0476` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0 'instr'
                      1334818 ~4%       {2}    | JOIN WITH num#AliasedSSA::TAllAliasedMemory#4bb632db ON FIRST 2 OUTPUT Rhs.2 'result', Lhs.2 'instr'
                      1334818 ~2%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      363138  ~1%       {2} r5 = JOIN r3 WITH num#MemoryAccessKind::TNonLocalMemoryAccess#b2a59f45 ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                      363138  ~1%       {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)
                      363138  ~5%       {3}    | JOIN WITH `SSAConstruction::getInstructionEnclosingIRFunction/1#d26c0476` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0 'instr'
                      363138  ~0%       {2}    | JOIN WITH num#AliasedSSA::TAllNonLocalMemory#7ba9f6c9 ON FIRST 2 OUTPUT Rhs.2 'result', Lhs.2 'instr'
                      363138  ~0%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      1086950 ~5%       {2} r6 = JOIN r3 WITH `AliasedSSA::isIndirectOrBufferMemoryAccess/1#a6492554` ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                      1086950 ~5%       {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)

                      141434  ~0%       {2} r7 = r6 AND NOT `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#7`(FIRST 1)
                      141434  ~0%       {3}    | JOIN WITH `SSAConstruction::getInstructionEnclosingIRFunction/1#d26c0476` ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0 'instr'
                      141434  ~5%       {2}    | JOIN WITH num#AliasedSSA::TUnknownMemoryLocation#e0c2a990 ON FIRST 2 OUTPUT Rhs.2 'result', Lhs.2 'instr'
                      141434  ~0%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      180541  ~0%       {2} r8 = JOIN r3 WITH num#MemoryAccessKind::TEntireAllocationMemoryAccess#503d0afb ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2
                      180541  ~0%       {2}    | AND NOT `AliasedSSA::canReuseSsaForOldResult/1#280fbda5`(FIRST 1)
                      180541  ~3%       {4}    | JOIN WITH `Instruction::Instruction.getResultAddressOperand/0#dispred#619d4407` ON FIRST 1 OUTPUT Rhs.1, Lhs.0 'instr', _, Lhs.1
                      180541  ~0%       {3}    | REWRITE WITH Out.2 := booleanNot(In.3) KEEPING 3
                      175074  ~2%       {3}    | JOIN WITH `project#AliasAnalysis::addressOperandAllocationAndOffset/3#c64a9862` ON FIRST 1 OUTPUT Rhs.1, Lhs.1 'instr', Lhs.2
                      349412  ~0%       {4}    | JOIN WITH num#AliasedSSA::TEntireAllocationMemoryLocation#85bb24dd ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.2, Rhs.1, Rhs.2 'result'
                                        {4}    | REWRITE WITH TEST InOut.1 != InOut.2
                      174706  ~1%       {2}    | SCAN OUTPUT In.3 'result', In.0 'instr'
                      174706  ~3%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      946577  ~0%       {5} r9 = JOIN r6 WITH `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#5_0512346#join_rhs` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.1, Rhs.2, Rhs.6, _
                                        {4}    | REWRITE WITH Tmp.4 := false, TEST InOut.3 != Tmp.4 KEEPING 4
                      2122    ~6%       {5}    | SCAN OUTPUT In.2, _, In.0 'instr', _, In.1
                      2122    ~0%       {4}    | REWRITE WITH Out.1 := false, Out.3 := booleanNot(In.4) KEEPING 4
                      4244    ~104%     {4}    | JOIN WITH `AliasedSSA::getGroupedMemoryLocation/3#14ef79fc#ffbf_0213#join_rhs` ON FIRST 2 OUTPUT Lhs.2 'instr', Lhs.3, Rhs.2, Rhs.3 'result'
                                        {4}    | REWRITE WITH TEST InOut.1 != InOut.2
                      2122    ~98%      {2}    | SCAN OUTPUT In.3 'result', In.0 'instr'
                      1061    ~0%       {2}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.0 'result'

                      946577  ~0%       {8} r10 = JOIN r6 WITH `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#5_0512346#join_rhs` ON FIRST 2 OUTPUT Lhs.0 'instr', Lhs.1, Rhs.2, Rhs.3, Rhs.4, Rhs.5, Rhs.6, _
                                        {7}    | REWRITE WITH Tmp.7 := false, TEST InOut.6 = Tmp.7 KEEPING 7
                      944455  ~0%       {6}    | SCAN OUTPUT In.2, In.3, In.4, In.5, In.0 'instr', In.1
                      1183383 ~2%       {8}    | JOIN WITH num#AliasedSSA::TVariableMemoryLocation#8e8cb20c_013456#join_rhs ON FIRST 4 OUTPUT Rhs.5 'result', Lhs.4 'instr', Lhs.5, Lhs.0, Lhs.1, Lhs.2, Lhs.3, Rhs.4
                      1183383 ~0%       {8}    | JOIN WITH AliasedSSA::MemoryLocation#4b9f223c ON FIRST 1 OUTPUT Lhs.1 'instr', Lhs.3, Lhs.4, Lhs.5, Lhs.6, Lhs.2, Lhs.7, Lhs.0 'result'
                      1183383 ~0%       {5}    | JOIN WITH `project#AliasedSSA::hasResultMemoryAccess/9#732473d4#6` ON FIRST 6 OUTPUT Lhs.0 'instr', Lhs.6, Lhs.7 'result', _, Lhs.5
                                        {4}    | REWRITE WITH Out.3 := booleanNot(In.4), TEST Out.3 != InOut.1 KEEPING 4
                      944455  ~3%       {2}    | SCAN OUTPUT In.0 'instr', In.2 'result'

                      2959612 ~0%       {2} r11 = r4 UNION r5 UNION r7 UNION r8 UNION r9 UNION r10
                                        return r11
```
  • Loading branch information
jketema committed Jan 11, 2025
1 parent fb047a6 commit 3f093ae
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,24 @@ class MemoryLocation extends FinalMemoryLocation {
MemoryLocation() { not useOverlapWithBusyDef(this) }
}

bindingset[fun]
pragma[inline_late]
private MemoryLocation getUnknownMemoryLocation(IRFunction fun, boolean isMayAccess) {
result = TUnknownMemoryLocation(fun, isMayAccess)
}

bindingset[fun]
pragma[inline_late]
private MemoryLocation getAllAliasedMemory(IRFunction fun, boolean isMayAccess) {
result = TAllAliasedMemory(fun, isMayAccess)
}

bindingset[fun]
pragma[inline_late]
private MemoryLocation getAllNonLocalMemory(IRFunction fun, boolean isMayAccess) {
result = TAllNonLocalMemory(fun, isMayAccess)
}

MemoryLocation getResultMemoryLocation(Instruction instr) {
not canReuseSsaForOldResult(instr) and
exists(MemoryAccessKind kind, boolean isMayAccess |
Expand Down Expand Up @@ -926,7 +944,7 @@ MemoryLocation getResultMemoryLocation(Instruction instr) {
// And otherwise we assign it a memory location that groups all the relevant memory locations into one.
result = getGroupedMemoryLocation(var, unbindBool(isMayAccess), false)
)
else result = TUnknownMemoryLocation(instr.getEnclosingIRFunction(), isMayAccess)
else result = getUnknownMemoryLocation(instr.getEnclosingIRFunction(), isMayAccess)
)
or
kind instanceof EntireAllocationMemoryAccess and
Expand All @@ -935,10 +953,10 @@ MemoryLocation getResultMemoryLocation(Instruction instr) {
unbindBool(isMayAccess))
or
kind instanceof EscapedMemoryAccess and
result = TAllAliasedMemory(instr.getEnclosingIRFunction(), isMayAccess)
result = getAllAliasedMemory(instr.getEnclosingIRFunction(), isMayAccess)
or
kind instanceof NonLocalMemoryAccess and
result = TAllNonLocalMemory(instr.getEnclosingIRFunction(), isMayAccess)
result = getAllNonLocalMemory(instr.getEnclosingIRFunction(), isMayAccess)
)
)
}
Expand Down

0 comments on commit 3f093ae

Please sign in to comment.