Skip to content

Commit be82be2

Browse files
[LLVM][GlobalISel] Ensure G_{F}CONSTANT only store references to scalar Constant{Int,FP}. (#137319)
1 parent dd87127 commit be82be2

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -3645,11 +3645,17 @@ bool IRTranslator::translate(const Constant &C, Register Reg) {
36453645
if (auto CurrInstDL = CurBuilder->getDL())
36463646
EntryBuilder->setDebugLoc(DebugLoc());
36473647

3648-
if (auto CI = dyn_cast<ConstantInt>(&C))
3648+
if (auto CI = dyn_cast<ConstantInt>(&C)) {
3649+
// buildConstant expects a to-be-splatted scalar ConstantInt.
3650+
if (isa<VectorType>(CI->getType()))
3651+
CI = ConstantInt::get(CI->getContext(), CI->getValue());
36493652
EntryBuilder->buildConstant(Reg, *CI);
3650-
else if (auto CF = dyn_cast<ConstantFP>(&C))
3653+
} else if (auto CF = dyn_cast<ConstantFP>(&C)) {
3654+
// buildFConstant expects a to-be-splatted scalar ConstantFP.
3655+
if (isa<VectorType>(CF->getType()))
3656+
CF = ConstantFP::get(CF->getContext(), CF->getValue());
36513657
EntryBuilder->buildFConstant(Reg, *CF);
3652-
else if (isa<UndefValue>(C))
3658+
} else if (isa<UndefValue>(C))
36533659
EntryBuilder->buildUndef(Reg);
36543660
else if (isa<ConstantPointerNull>(C))
36553661
EntryBuilder->buildConstant(Reg, 0);

llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ MachineInstrBuilder MachineIRBuilder::buildCopy(const DstOp &Res,
316316

317317
MachineInstrBuilder MachineIRBuilder::buildConstant(const DstOp &Res,
318318
const ConstantInt &Val) {
319+
assert(!isa<VectorType>(Val.getType()) && "Unexpected vector constant!");
319320
LLT Ty = Res.getLLTTy(*getMRI());
320321
LLT EltTy = Ty.getScalarType();
321322
assert(EltTy.getScalarSizeInBits() == Val.getBitWidth() &&
@@ -348,6 +349,7 @@ MachineInstrBuilder MachineIRBuilder::buildConstant(const DstOp &Res,
348349

349350
MachineInstrBuilder MachineIRBuilder::buildFConstant(const DstOp &Res,
350351
const ConstantFP &Val) {
352+
assert(!isa<VectorType>(Val.getType()) && "Unexpected vector constant!");
351353
LLT Ty = Res.getLLTTy(*getMRI());
352354
LLT EltTy = Ty.getScalarType();
353355

llvm/test/CodeGen/AArch64/neon-mov.ll

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc < %s -verify-machineinstrs -mtriple=aarch64-none-linux-gnu -mattr=+neon | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16,CHECK-NOFP16-SD
3-
; RUN: llc < %s -verify-machineinstrs -mtriple=aarch64-none-linux-gnu -mattr=+neon,+fullfp16 | FileCheck %s --check-prefixes=CHECK,CHECK-FP16,CHECK-FP16-SD
4-
; RUN: llc -mtriple=aarch64-none-linux-gnu -mattr=+neon -global-isel %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16,CHECK-NOFP16-GI
5-
; RUN: llc -mtriple=aarch64-none-linux-gnu -mattr=+neon,+fullfp16 -global-isel %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16,CHECK-FP16-GI
2+
; RUN: llc < %s -verify-machineinstrs -mattr=+neon | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16,CHECK-NOFP16-SD
3+
; RUN: llc < %s -verify-machineinstrs -mattr=+neon,+fullfp16 | FileCheck %s --check-prefixes=CHECK,CHECK-FP16,CHECK-FP16-SD
4+
; RUN: llc -mattr=+neon -global-isel %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16,CHECK-NOFP16-GI
5+
; RUN: llc -mattr=+neon,+fullfp16 -global-isel %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16,CHECK-FP16-GI
6+
7+
; This are copies of the above RUN lines but with vector constants enabled.
8+
; RUN: llc -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat < %s -verify-machineinstrs -mattr=+neon | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16,CHECK-NOFP16-SD
9+
; RUN: llc -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat < %s -verify-machineinstrs -mattr=+neon,+fullfp16 | FileCheck %s --check-prefixes=CHECK,CHECK-FP16,CHECK-FP16-SD
10+
; RUN: llc -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat -mattr=+neon -global-isel %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16,CHECK-NOFP16-GI
11+
; RUN: llc -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat -mattr=+neon,+fullfp16 -global-isel %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16,CHECK-FP16-GI
12+
13+
target triple = "aarch64-none-linux-gnu"
614

715
define <8 x i8> @movi8b_0() {
816
; CHECK-LABEL: movi8b_0:

0 commit comments

Comments
 (0)