Fix invalid alignment in DAGCombiner::isLegalNarrowLdSt

`ShAmt / 8` can be a non power of two, this can lead to an invalid alignment.
context: https://reviews.llvm.org/D41350#inline-749165

Differential Revision: https://reviews.llvm.org/D82565
This commit is contained in:
Guillaume Chatelet 2020-06-29 09:22:15 +00:00
parent e34523c87c
commit 3500d9ec95
2 changed files with 20 additions and 16 deletions

View File

@ -4875,11 +4875,16 @@ bool DAGCombiner::isLegalNarrowLdSt(LSBaseSDNode *LDST,
return false;
// Ensure that this isn't going to produce an unsupported memory access.
if (ShAmt &&
!TLI.allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), MemVT,
LDST->getAddressSpace(), ShAmt / 8,
if (ShAmt) {
assert(ShAmt % 8 == 0 && "ShAmt is byte offset");
const unsigned ByteShAmt = ShAmt / 8;
const Align LDSTAlign = LDST->getAlign();
const Align NarrowAlign = commonAlignment(LDSTAlign, ByteShAmt);
if (!TLI.allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), MemVT,
LDST->getAddressSpace(), NarrowAlign.value(),
LDST->getMemOperand()->getFlags()))
return false;
}
// It's not possible to generate a constant of extended or untyped type.
EVT PtrType = LDST->getBasePtr().getValueType();

View File

@ -1433,12 +1433,9 @@ define arm_aapcscc i64 @test23(i64* nocapture %p) {
;
; THUMB1-LABEL: test23:
; THUMB1: @ %bb.0:
; THUMB1-NEXT: ldrb r1, [r0, #3]
; THUMB1-NEXT: ldrb r0, [r0, #4]
; THUMB1-NEXT: lsls r0, r0, #8
; THUMB1-NEXT: adds r1, r0, r1
; THUMB1-NEXT: lsls r0, r1, #24
; THUMB1-NEXT: lsrs r1, r1, #8
; THUMB1-NEXT: ldrb r1, [r0, #4]
; THUMB1-NEXT: ldrb r0, [r0, #3]
; THUMB1-NEXT: lsls r0, r0, #24
; THUMB1-NEXT: bx lr
;
; THUMB2-LABEL: test23:
@ -1498,13 +1495,15 @@ define arm_aapcscc i64 @test25(i64* nocapture %p) {
;
; THUMB1-LABEL: test25:
; THUMB1: @ %bb.0:
; THUMB1-NEXT: ldrb r1, [r0, #5]
; THUMB1-NEXT: ldrb r0, [r0, #6]
; THUMB1-NEXT: lsls r0, r0, #8
; THUMB1-NEXT: adds r0, r0, r1
; THUMB1-NEXT: lsls r1, r0, #8
; THUMB1-NEXT: ldr r0, [r0, #4]
; THUMB1-NEXT: ldr r1, .LCPI37_0
; THUMB1-NEXT: ands r1, r0
; THUMB1-NEXT: movs r0, #0
; THUMB1-NEXT: bx lr
; THUMB1-NEXT: .p2align 2
; THUMB1-NEXT: @ %bb.1:
; THUMB1-NEXT: .LCPI37_0:
; THUMB1-NEXT: .long 16776960 @ 0xffff00
;
; THUMB2-LABEL: test25:
; THUMB2: @ %bb.0: