Skip to content

Commit 730e8f6

Browse files
committed
[AArch64][GlobalISel] Fix global offset folding combine inserting MIs into wrong place.
Was causing use-before-def issues. Not sure how it remained undetected for so long.
1 parent bf1bcb6 commit 730e8f6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void applyFoldGlobalOffset(MachineInstr &MI, MachineRegisterInfo &MRI,
214214
// %ptrN = G_PTR_ADD %offset_g, cstN - min_cst
215215
uint64_t Offset, MinOffset;
216216
std::tie(Offset, MinOffset) = MatchInfo;
217-
B.setInstrAndDebugLoc(MI);
217+
B.setInstrAndDebugLoc(*std::next(MI.getIterator()));
218218
Observer.changingInstr(MI);
219219
auto &GlobalOp = MI.getOperand(1);
220220
auto *GV = GlobalOp.getGlobal();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
2+
# RUN: llc -mtriple aarch64-apple-darwin -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s
3+
--- |
4+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5+
target triple = "arm64-apple-macosx13.5.0"
6+
7+
%struct.wibble = type <{ [500 x %struct.wobble], [500 x %struct.wobble], [500 x %struct.wobble], [500 x %struct.wobble], [500 x %struct.wobble], i32, i32, i32, i32, i32, i32, %struct.baz, float, float, float, float, float, [4 x i8] }>
8+
%struct.wobble = type { [4 x float] }
9+
%struct.baz = type { %struct.foo }
10+
%struct.foo = type { i64, i32 }
11+
12+
@global = global %struct.wibble zeroinitializer
13+
14+
define void @wibble() {
15+
ret void
16+
}
17+
18+
...
19+
---
20+
name: wibble
21+
body: |
22+
bb.1:
23+
; CHECK-LABEL: name: wibble
24+
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
25+
; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @global + 40004
26+
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
27+
; CHECK-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[GV]], [[C1]](s64)
28+
; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR [[C]](s32), [[C]](s32), [[C]](s32), [[C]](s32)
29+
; CHECK-NEXT: G_STORE [[C]](s32), [[PTR_ADD]](p0) :: (store (s32) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 10)`)
30+
; CHECK-NEXT: G_STORE [[BUILD_VECTOR]](<4 x s32>), [[GV]](p0) :: (store (<4 x s32>) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 6)`, align 4)
31+
; CHECK-NEXT: RET_ReallyLR
32+
%0:_(s32) = G_CONSTANT i32 0
33+
%2:_(p0) = G_GLOBAL_VALUE @global
34+
%3:_(s64) = G_CONSTANT i64 40020
35+
%1:_(p0) = G_PTR_ADD %2, %3(s64)
36+
%4:_(<4 x s32>) = G_BUILD_VECTOR %0(s32), %0(s32), %0(s32), %0(s32)
37+
%6:_(s64) = G_CONSTANT i64 40004
38+
%5:_(p0) = G_PTR_ADD %2, %6(s64)
39+
G_STORE %0(s32), %1(p0) :: (store (s32) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 10)`)
40+
G_STORE %4(<4 x s32>), %5(p0) :: (store (<4 x s32>) into `ptr getelementptr inbounds (%struct.wibble, ptr @global, i64 0, i32 6)`, align 4)
41+
RET_ReallyLR
42+
43+
...

0 commit comments

Comments
 (0)