Skip to content

Commit de1b30b

Browse files
[EVM] Don't emit JUMPDEST in entry point of bytecode
We don't need to emit JUMPDEST instruction in the first BB of the __entry function. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent 45b8694 commit de1b30b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/Target/EVM/EVMAsmPrinter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,18 @@ void EVMAsmPrinter::emitFunctionBodyEnd() { FirstFunctIsHandled = true; }
127127
void EVMAsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
128128
AsmPrinter::emitBasicBlockStart(MBB);
129129

130+
// If this is __entry function, we don't need to emit JUMPDEST
131+
// instruction in the first basic block, as it is the entry point
132+
// of the EVM bytecode.
133+
auto IsEntryPoint = [this](const MachineBasicBlock &MBB) {
134+
return !FirstFunctIsHandled && &MBB == &MF->front() &&
135+
MF->getName() == "__entry";
136+
};
137+
130138
// Emit JUMPDEST instruction at the beginning of the basic block, if
131139
// this is not a block that is only reachable by fallthrough.
132-
if (!EVMKeepRegisters && !AsmPrinter::isBlockOnlyReachableByFallthrough(&MBB))
140+
if (!EVMKeepRegisters && !IsEntryPoint(MBB) &&
141+
!AsmPrinter::isBlockOnlyReachableByFallthrough(&MBB))
133142
emitJumpDest();
134143
}
135144

llvm/test/CodeGen/EVM/jumpdest-in-entry-point.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ declare void @llvm.evm.return(ptr addrspace(1), i256)
99
define void @__entry() noreturn {
1010
; CHECK-LABEL: __entry:
1111
; CHECK: ; %bb.0: ; %entry
12-
; CHECK-NEXT: JUMPDEST
1312
; CHECK-NEXT: PUSH0
1413
; CHECK-NEXT: MLOAD
1514
; CHECK-NEXT: DUP1

0 commit comments

Comments
 (0)