Skip to content

Commit d714b22

Browse files
authored
[AArch64] Guard against getRegisterBitWidth returning zero in vector instr cost. (#117749)
If the getRegisterBitWidth is zero (such as in sme streaming functions), then we could hit a crash from using % RegWidth.
1 parent dab9fa2 commit d714b22

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3259,7 +3259,7 @@ InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
32593259
auto RegWidth =
32603260
getRegisterBitWidth(TargetTransformInfo::RGK_FixedWidthVector)
32613261
.getFixedValue();
3262-
return (Idx == 0 || (Idx * EltSz) % RegWidth == 0);
3262+
return Idx == 0 || (RegWidth != 0 && (Idx * EltSz) % RegWidth == 0);
32633263
};
32643264

32653265
// Check if the type constraints on input vector type and result scalar type
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=aarch64-unknown-linux -mattr=+sme | FileCheck %s
3+
4+
define double @extract_case7(<4 x double> %a) "aarch64_pstate_sm_enabled" {
5+
; CHECK-LABEL: 'extract_case7'
6+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %0 = extractelement <4 x double> %a, i32 1
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %1 = extractelement <4 x double> %a, i32 2
8+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %res = fmul double %0, %1
9+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret double %res
10+
;
11+
entry:
12+
%1 = extractelement <4 x double> %a, i32 1
13+
%2 = extractelement <4 x double> %a, i32 2
14+
%res = fmul double %1, %2
15+
ret double %res
16+
}
17+
18+
declare void @foo(double)

0 commit comments

Comments
 (0)