Skip to content

Commit 3275291

Browse files
authored
[ARM] Do not assume memory intrinsics specify alignment. (#138356)
1 parent 5f7213e commit 3275291

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,8 @@ int ARMTTIImpl::getNumMemOps(const IntrinsicInst *I) const {
11691169
return -1;
11701170

11711171
const unsigned Size = C->getValue().getZExtValue();
1172-
const Align DstAlign = *MC->getDestAlign();
1173-
const Align SrcAlign = *MC->getSourceAlign();
1172+
const Align DstAlign = MC->getDestAlign().valueOrOne();
1173+
const Align SrcAlign = MC->getSourceAlign().valueOrOne();
11741174

11751175
MOp = MemOp::Copy(Size, /*DstAlignCanChange*/ false, DstAlign, SrcAlign,
11761176
/*IsVolatile*/ false);
@@ -1184,7 +1184,7 @@ int ARMTTIImpl::getNumMemOps(const IntrinsicInst *I) const {
11841184
return -1;
11851185

11861186
const unsigned Size = C->getValue().getZExtValue();
1187-
const Align DstAlign = *MS->getDestAlign();
1187+
const Align DstAlign = MS->getDestAlign().valueOrOne();
11881188

11891189
MOp = MemOp::Set(Size, /*DstAlignCanChange*/ false, DstAlign,
11901190
/*IsZeroMemset*/ false, /*IsVolatile*/ false);

llvm/test/Analysis/CostModel/ARM/memcpy.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ target triple = "thumbv7m-arm-unknown-eabi"
1111
; Align 1, 1
1212
;;;;;;;;;;;;
1313

14+
define void @memcpy_0(ptr %d, ptr %s) {
15+
;
16+
; with/without strict-align:
17+
;
18+
; ldrb r1, [r1]
19+
; strb r1, [r0]
20+
;
21+
; COMMON-LABEL: 'memcpy_0'
22+
; COMMON-NEXT: Cost Model: Found an estimated cost of 2 for instruction: call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 1, i1 false)
23+
; COMMON-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
24+
;
25+
entry:
26+
call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 1, i1 false)
27+
ret void
28+
}
29+
1430
define void @memcpy_1(ptr %d, ptr %s) {
1531
;
1632
; with/without strict-align:

0 commit comments

Comments
 (0)