Skip to content

Commit d623479

Browse files
vladimirradosavljevicakiramenai
authored andcommitted
[EVM] Set that gas intrinsic doesn't access storage memory
This will help optimizations that use alias analysis to search past it, and to optimize further. Benchmark numbers showed that this is not profitable to do for heap address space. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent 5ecef9a commit d623479

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

llvm/include/llvm/IR/IntrinsicsEVM.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def int_evm_msize : Intrinsic<[llvm_i256_ty], [], [IntrWillReturn]>;
108108

109109
def int_evm_pc : Intrinsic<[llvm_i256_ty], [], [IntrWillReturn]>;
110110

111+
// TODO: #904: Set IntrInaccessibleMemOnly attribute to gas intrinsic.
112+
// Currently, it is not set because benchmark numbers showed that it is not
113+
// profitable to do that for heap address space. Revisit this decision once
114+
// optimization for free ptr updates is implemented.
111115
def int_evm_gas : Intrinsic<[llvm_i256_ty], [], [IntrWillReturn]>;
112116

113117
// Getting values from the context.

llvm/lib/Target/EVM/EVMAliasAnalysis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ ModRefInfo EVMAAResult::getModRefInfo(const CallBase *Call,
108108

109109
unsigned AS = Loc.Ptr->getType()->getPointerAddressSpace();
110110
switch (II->getIntrinsicID()) {
111+
case Intrinsic::evm_gas:
112+
// TODO: #904: Ideally, we would add IntrInaccessibleMemOnly attribute to
113+
// gas intrinsic, but benchmark numbers showed that it is not profitable
114+
// to do that for heap address space.
115+
if (AS == EVMAS::AS_STORAGE || AS == EVMAS::AS_TSTORAGE)
116+
return ModRefInfo::NoModRef;
117+
return ModRefInfo::ModRef;
111118
case Intrinsic::evm_return:
112119
case Intrinsic::evm_staticcall:
113120
if (AS == EVMAS::AS_STORAGE || AS == EVMAS::AS_TSTORAGE)

llvm/test/CodeGen/EVM/aa-memory-opt.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ define i256 @test_different_locsizes() {
5353
ret i256 %ret
5454
}
5555

56+
; TODO: #904: It is safe to remove load in this test, but it is not done since benchmark
57+
; numbers showed that it is not profitable to do that for heap address space.
5658
define i256 @test_gas_as1() {
5759
; CHECK-LABEL: define i256 @test_gas_as1
5860
; CHECK-SAME: () local_unnamed_addr #[[ATTR2:[0-9]+]] {
@@ -74,8 +76,7 @@ define i256 @test_gas_as5() {
7476
; CHECK-SAME: () local_unnamed_addr #[[ATTR2]] {
7577
; CHECK-NEXT: store i256 2, ptr addrspace(5) inttoptr (i256 2 to ptr addrspace(5)), align 64
7678
; CHECK-NEXT: [[GAS:%.*]] = tail call i256 @llvm.evm.gas()
77-
; CHECK-NEXT: [[LOAD:%.*]] = load i256, ptr addrspace(5) inttoptr (i256 2 to ptr addrspace(5)), align 64
78-
; CHECK-NEXT: [[RET:%.*]] = add i256 [[LOAD]], [[GAS]]
79+
; CHECK-NEXT: [[RET:%.*]] = add i256 [[GAS]], 2
7980
; CHECK-NEXT: ret i256 [[RET]]
8081
;
8182
store i256 2, ptr addrspace(5) inttoptr (i256 2 to ptr addrspace(5)), align 64
@@ -90,8 +91,7 @@ define i256 @test_gas_as6() {
9091
; CHECK-SAME: () local_unnamed_addr #[[ATTR2]] {
9192
; CHECK-NEXT: store i256 2, ptr addrspace(6) inttoptr (i256 2 to ptr addrspace(6)), align 64
9293
; CHECK-NEXT: [[GAS:%.*]] = tail call i256 @llvm.evm.gas()
93-
; CHECK-NEXT: [[LOAD:%.*]] = load i256, ptr addrspace(6) inttoptr (i256 2 to ptr addrspace(6)), align 64
94-
; CHECK-NEXT: [[RET:%.*]] = add i256 [[LOAD]], [[GAS]]
94+
; CHECK-NEXT: [[RET:%.*]] = add i256 [[GAS]], 2
9595
; CHECK-NEXT: ret i256 [[RET]]
9696
;
9797
store i256 2, ptr addrspace(6) inttoptr (i256 2 to ptr addrspace(6)), align 64

0 commit comments

Comments
 (0)