@@ -45,19 +45,18 @@ bool EVMPeephole::runOnMachineFunction(MachineFunction &MF) {
45
45
return Changed;
46
46
}
47
47
48
- static bool isNegatadAndJumpedOn (const MachineBasicBlock &MBB,
48
+ static bool isNegatedAndJumpedOn (const MachineBasicBlock &MBB,
49
49
MachineBasicBlock::const_iterator I) {
50
50
if (I == MBB.end () || I->getOpcode () != EVM::ISZERO_S)
51
51
return false ;
52
52
++I;
53
- if (I == MBB.end ())
54
- return false ;
55
- if (I->getOpcode () == EVM::PseudoJUMPI)
56
- return true ;
57
- if (I->getOpcode () != EVM::PUSH4_S)
58
- return false ;
59
- ++I;
60
- return I != MBB.end () && I->getOpcode () == EVM::JUMPI;
53
+ // When a conditional jump’s predicate is a (possibly nested) bitwise `or`,
54
+ // both operands are eligible for folding. Currently we only fold the operand
55
+ // computed last.
56
+ // TODO: #887 Apply folding to all operands.
57
+ while (I != MBB.end () && I->getOpcode () == EVM::OR_S)
58
+ ++I;
59
+ return I != MBB.end () && I->getOpcode () == EVM::PseudoJUMPI;
61
60
}
62
61
63
62
bool EVMPeephole::optimizeConditionaJumps (MachineBasicBlock &MBB) const {
@@ -67,23 +66,23 @@ bool EVMPeephole::optimizeConditionaJumps(MachineBasicBlock &MBB) const {
67
66
while (I != MBB.end ()) {
68
67
// Fold ISZERO ISZERO to nothing, only if it's a predicate to JUMPI.
69
68
if (I->getOpcode () == EVM::ISZERO_S &&
70
- isNegatadAndJumpedOn (MBB, std::next (I))) {
69
+ isNegatedAndJumpedOn (MBB, std::next (I))) {
71
70
std::next (I)->eraseFromParent ();
72
71
I->eraseFromParent ();
73
72
return true ;
74
73
}
75
74
76
75
// Fold EQ ISZERO to SUB, only if it's a predicate to JUMPI.
77
76
if (I->getOpcode () == EVM::EQ_S &&
78
- isNegatadAndJumpedOn (MBB, std::next (I))) {
77
+ isNegatedAndJumpedOn (MBB, std::next (I))) {
79
78
I->setDesc (TII->get (EVM::SUB_S));
80
79
std::next (I)->eraseFromParent ();
81
80
return true ;
82
81
}
83
82
84
83
// Fold SUB ISZERO to EQ, only if it's a predicate to JUMPI.
85
84
if (I->getOpcode () == EVM::SUB_S &&
86
- isNegatadAndJumpedOn (MBB, std::next (I))) {
85
+ isNegatedAndJumpedOn (MBB, std::next (I))) {
87
86
I->setDesc (TII->get (EVM::EQ_S));
88
87
std::next (I)->eraseFromParent ();
89
88
return true ;
0 commit comments