Skip to content

Commit db70035

Browse files
aemersonmemfrob
authored andcommitted
[GlobalISel] Fix non-pow-2 legalization of s56 stores.
s56 stores are broken down into s32 + s24 stores. During this step both of those new stores use an anyextended s64 value, resulting in truncating stores. With s56, the s24 requires another lower step to make it legal, and we were crashing because we didn't expect non-pow-2 stores to also be truncating as well. Differential Revision: https://reviews.llvm.org/D106183
1 parent 7755825 commit db70035

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,15 +2947,17 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerStore(GStore &StoreMI) {
29472947
if (isPowerOf2_32(MemTy.getSizeInBits()))
29482948
return UnableToLegalize; // Don't know what we're being asked to do.
29492949

2950-
// Extend to the next pow-2.
2951-
const LLT ExtendTy = LLT::scalar(NextPowerOf2(MemTy.getSizeInBits()));
2952-
auto ExtVal = MIRBuilder.buildAnyExt(ExtendTy, SrcReg);
2950+
// Extend to the next pow-2. If this store was itself the result of lowering,
2951+
// e.g. an s56 store being broken into s32 + s24, we might have a stored type
2952+
// that's wider the stored size.
2953+
const LLT NewSrcTy = LLT::scalar(NextPowerOf2(MemTy.getSizeInBits()));
2954+
auto ExtVal = MIRBuilder.buildAnyExtOrTrunc(NewSrcTy, SrcReg);
29532955

29542956
// Obtain the smaller value by shifting away the larger value.
29552957
uint64_t LargeSplitSize = PowerOf2Floor(MemTy.getSizeInBits());
2956-
uint64_t SmallSplitSize = SrcTy.getSizeInBits() - LargeSplitSize;
2957-
auto ShiftAmt = MIRBuilder.buildConstant(ExtendTy, LargeSplitSize);
2958-
auto SmallVal = MIRBuilder.buildLShr(ExtendTy, ExtVal, ShiftAmt);
2958+
uint64_t SmallSplitSize = MemTy.getSizeInBits() - LargeSplitSize;
2959+
auto ShiftAmt = MIRBuilder.buildConstant(NewSrcTy, LargeSplitSize);
2960+
auto SmallVal = MIRBuilder.buildLShr(NewSrcTy, ExtVal, ShiftAmt);
29592961

29602962
// Generate the PtrAdd and truncating stores.
29612963
LLT PtrTy = MRI.getType(PtrReg);
Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,72 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -march=aarch64 -run-pass=legalizer %s -o - -verify-machineinstrs | FileCheck %s
3-
--- |
4-
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5-
target triple = "aarch64"
6-
7-
define i32 @load_store_test(i24* %ptr, i24* %ptr2) {
8-
%val = load i24, i24* %ptr
9-
store i24 %val, i24* %ptr2
10-
ret i32 0
11-
}
12-
13-
...
143
---
154
name: load_store_test
165
alignment: 4
176
tracksRegLiveness: true
187
body: |
19-
bb.1 (%ir-block.0):
8+
bb.1:
209
liveins: $x0, $x1
2110
2211
; CHECK-LABEL: name: load_store_test
2312
; CHECK: liveins: $x0, $x1
2413
; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
2514
; CHECK: [[COPY1:%[0-9]+]]:_(p0) = COPY $x1
2615
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
27-
; CHECK: [[ZEXTLOAD:%[0-9]+]]:_(s32) = G_ZEXTLOAD [[COPY]](p0) :: (load (s16) from %ir.ptr, align 4)
16+
; CHECK: [[ZEXTLOAD:%[0-9]+]]:_(s32) = G_ZEXTLOAD [[COPY]](p0) :: (load (s16), align 4)
2817
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 2
2918
; CHECK: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C1]](s64)
30-
; CHECK: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p0) :: (load (s8) from %ir.ptr + 2, align 2, basealign 4)
19+
; CHECK: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p0) :: (load (s8) from unknown-address + 2, align 2)
3120
; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
3221
; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[LOAD]], [[C2]](s64)
3322
; CHECK: [[OR:%[0-9]+]]:_(s32) = G_OR [[SHL]], [[ZEXTLOAD]]
3423
; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[OR]](s32)
3524
; CHECK: [[LSHR:%[0-9]+]]:_(s32) = G_LSHR [[COPY2]], [[C2]](s64)
3625
; CHECK: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY1]], [[C1]](s64)
37-
; CHECK: G_STORE [[COPY2]](s32), [[COPY1]](p0) :: (store (s16) into %ir.ptr2, align 4)
38-
; CHECK: G_STORE [[LSHR]](s32), [[PTR_ADD1]](p0) :: (store (s8) into %ir.ptr2 + 2, align 2, basealign 4)
26+
; CHECK: G_STORE [[COPY2]](s32), [[COPY1]](p0) :: (store (s16), align 4)
27+
; CHECK: G_STORE [[LSHR]](s32), [[PTR_ADD1]](p0) :: (store (s8) into unknown-address + 2, align 2)
3928
; CHECK: $w0 = COPY [[C]](s32)
4029
; CHECK: RET_ReallyLR implicit $w0
4130
%0:_(p0) = COPY $x0
4231
%1:_(p0) = COPY $x1
4332
%3:_(s32) = G_CONSTANT i32 0
44-
%2:_(s24) = G_LOAD %0(p0) :: (load (s24) from %ir.ptr, align 4)
45-
G_STORE %2(s24), %1(p0) :: (store (s24) into %ir.ptr2, align 4)
33+
%2:_(s24) = G_LOAD %0(p0) :: (load (s24), align 4)
34+
G_STORE %2(s24), %1(p0) :: (store (s24), align 4)
4635
$w0 = COPY %3(s32)
4736
RET_ReallyLR implicit $w0
4837
4938
...
39+
---
40+
name: store_i56
41+
alignment: 4
42+
tracksRegLiveness: true
43+
liveins:
44+
- { reg: '$x0' }
45+
body: |
46+
bb.1:
47+
liveins: $x0
48+
49+
; CHECK-LABEL: name: store_i56
50+
; CHECK: liveins: $x0
51+
; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
52+
; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
53+
; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY [[C]](s64)
54+
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
55+
; CHECK: [[LSHR:%[0-9]+]]:_(s64) = G_LSHR [[COPY1]], [[C1]](s64)
56+
; CHECK: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
57+
; CHECK: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C2]](s64)
58+
; CHECK: G_STORE [[COPY1]](s64), [[COPY]](p0) :: (store (s32), align 8)
59+
; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[LSHR]](s64)
60+
; CHECK: [[C3:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
61+
; CHECK: [[LSHR1:%[0-9]+]]:_(s32) = G_LSHR [[TRUNC]], [[C3]](s64)
62+
; CHECK: [[C4:%[0-9]+]]:_(s64) = G_CONSTANT i64 2
63+
; CHECK: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[PTR_ADD]], [[C4]](s64)
64+
; CHECK: G_STORE [[TRUNC]](s32), [[PTR_ADD]](p0) :: (store (s16) into unknown-address + 4, align 4)
65+
; CHECK: G_STORE [[LSHR1]](s32), [[PTR_ADD1]](p0) :: (store (s8) into unknown-address + 6, align 2)
66+
; CHECK: RET_ReallyLR
67+
%0:_(p0) = COPY $x0
68+
%1:_(s56) = G_CONSTANT i56 32
69+
G_STORE %1(s56), %0(p0) :: (store (s56), align 8)
70+
RET_ReallyLR
71+
72+
...

0 commit comments

Comments
 (0)