Skip to content

Commit 0bfbd3e

Browse files
[CGP] Fix missing sign extension for base offset in optimizeMemoryInst
If we have integers larger than 64-bit we need to explicitly sign extend them, otherwise we will get wrong zero extended values. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent 0d19eb1 commit 0bfbd3e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5706,7 +5706,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
57065706

57075707
// Add in the Base Offset if present.
57085708
if (AddrMode.BaseOffs) {
5709-
Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs);
5709+
Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs, true);
57105710
if (ResultIndex) {
57115711
// We need to add this separately from the scale above to help with
57125712
// SDAG consecutive load/store merging.
@@ -5825,7 +5825,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
58255825

58265826
// Add in the Base Offset if present.
58275827
if (AddrMode.BaseOffs) {
5828-
Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs);
5828+
Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs, true);
58295829
if (Result)
58305830
Result = Builder.CreateAdd(Result, V, "sunkaddr");
58315831
else
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' < %s | FileCheck --check-prefix=GEP %s
2+
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -addr-sink-using-gep=false < %s | FileCheck --check-prefix=NO-GEP %s
3+
4+
target datalayout = "E-p:256:256-i256:256:256-S256-a:256:256"
5+
target triple = "evm"
6+
7+
; GEP-LABEL: @test(
8+
; GEP: getelementptr i8, ptr addrspace(1) {{.*}}, i256 -32
9+
; GEP-NOT: getelementptr i8, ptr addrspace(1) {{.*}}, i256 18446744073709551584
10+
11+
; NO-GEP-LABEL: @test(
12+
; NO-GEP: add i256 {{.*}}, -32
13+
; NO-GEP-NOT: add i256 {{.*}}, 18446744073709551584
14+
15+
define i256 @test(i256 %arg) {
16+
entry:
17+
%add = add i256 %arg, -32
18+
%cmp = icmp ugt i256 %arg, 10
19+
br i1 %cmp, label %then, label %exit
20+
21+
then:
22+
%inttoptr = inttoptr i256 %add to ptr addrspace(1)
23+
%load = load i256, ptr addrspace(1) %inttoptr, align 1
24+
br label %exit
25+
26+
exit:
27+
%phi = phi i256 [ %load, %then ], [ 0, %entry ]
28+
ret i256 %phi
29+
}

0 commit comments

Comments
 (0)