Skip to content

Commit 0de6baa

Browse files
committed
[AArch64][GlobalISel] Look through COPY and G_BITCAST while selecting fcvtl2 (fpext)
It tackles some regressions introduced in https://reviews.llvm.org/D144670.
1 parent 69036eb commit 0de6baa

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6777,11 +6777,29 @@ AArch64InstructionSelector::selectExtractHigh(MachineOperand &Root) const {
67776777
MachineRegisterInfo &MRI =
67786778
Root.getParent()->getParent()->getParent()->getRegInfo();
67796779

6780-
MachineInstr *Extract = getDefIgnoringCopies(Root.getReg(), MRI);
6781-
if (Extract && Extract->getOpcode() == TargetOpcode::G_UNMERGE_VALUES &&
6782-
Root.getReg() == Extract->getOperand(1).getReg()) {
6783-
Register ExtReg = Extract->getOperand(2).getReg();
6784-
return {{[=](MachineInstrBuilder &MIB) { MIB.addUse(ExtReg); }}};
6780+
auto Extract = getDefSrcRegIgnoringCopies(Root.getReg(), MRI);
6781+
while (Extract && Extract->MI->getOpcode() == TargetOpcode::G_BITCAST &&
6782+
STI.isLittleEndian())
6783+
Extract =
6784+
getDefSrcRegIgnoringCopies(Extract->MI->getOperand(1).getReg(), MRI);
6785+
if (!Extract)
6786+
return std::nullopt;
6787+
6788+
if (Extract->MI->getOpcode() == TargetOpcode::G_UNMERGE_VALUES) {
6789+
if (Extract->Reg == Extract->MI->getOperand(1).getReg()) {
6790+
Register ExtReg = Extract->MI->getOperand(2).getReg();
6791+
return {{[=](MachineInstrBuilder &MIB) { MIB.addUse(ExtReg); }}};
6792+
}
6793+
}
6794+
if (Extract->MI->getOpcode() == TargetOpcode::G_EXTRACT_VECTOR_ELT) {
6795+
LLT SrcTy = MRI.getType(Extract->MI->getOperand(1).getReg());
6796+
auto LaneIdx = getIConstantVRegValWithLookThrough(
6797+
Extract->MI->getOperand(2).getReg(), MRI);
6798+
if (LaneIdx && SrcTy == LLT::fixed_vector(2, 64) &&
6799+
LaneIdx->Value.getSExtValue() == 1) {
6800+
Register ExtReg = Extract->MI->getOperand(1).getReg();
6801+
return {{[=](MachineInstrBuilder &MIB) { MIB.addUse(ExtReg); }}};
6802+
}
67856803
}
67866804

67876805
return std::nullopt;

llvm/test/CodeGen/AArch64/arm64-vcvt_f.ll

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ define <2 x double> @test_vcvt_high_v1f64_f32_bitcast(<4 x float> %x) nounwind r
4646
;
4747
; GISEL-LABEL: test_vcvt_high_v1f64_f32_bitcast:
4848
; GISEL: // %bb.0:
49-
; GISEL-NEXT: mov d0, v0[1]
50-
; GISEL-NEXT: fcvtl v0.2d, v0.2s
49+
; GISEL-NEXT: fcvtl2 v0.2d, v0.4s
5150
; GISEL-NEXT: ret
5251
%bc1 = bitcast <4 x float> %x to <2 x double>
5352
%ext = shufflevector <2 x double> %bc1, <2 x double> undef, <1 x i32> <i32 1>
@@ -64,8 +63,7 @@ define <2 x double> @test_vcvt_high_v1i64_f32_bitcast(<2 x i64> %x) nounwind rea
6463
;
6564
; GISEL-LABEL: test_vcvt_high_v1i64_f32_bitcast:
6665
; GISEL: // %bb.0:
67-
; GISEL-NEXT: mov d0, v0[1]
68-
; GISEL-NEXT: fcvtl v0.2d, v0.2s
66+
; GISEL-NEXT: fcvtl2 v0.2d, v0.4s
6967
; GISEL-NEXT: ret
7068
%ext = shufflevector <2 x i64> %x, <2 x i64> undef, <1 x i32> <i32 1>
7169
%bc2 = bitcast <1 x i64> %ext to <2 x float>
@@ -97,8 +95,7 @@ define <2 x double> @test_vcvt_high_v4i16_f32_bitcast(<8 x i16> %x) nounwind rea
9795
;
9896
; GISEL-LABEL: test_vcvt_high_v4i16_f32_bitcast:
9997
; GISEL: // %bb.0:
100-
; GISEL-NEXT: mov d0, v0[1]
101-
; GISEL-NEXT: fcvtl v0.2d, v0.2s
98+
; GISEL-NEXT: fcvtl2 v0.2d, v0.4s
10299
; GISEL-NEXT: ret
103100
%ext = shufflevector <8 x i16> %x, <8 x i16> undef, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
104101
%bc2 = bitcast <4 x i16> %ext to <2 x float>
@@ -114,8 +111,7 @@ define <2 x double> @test_vcvt_high_v8i8_f32_bitcast(<16 x i8> %x) nounwind read
114111
;
115112
; GISEL-LABEL: test_vcvt_high_v8i8_f32_bitcast:
116113
; GISEL: // %bb.0:
117-
; GISEL-NEXT: mov d0, v0[1]
118-
; GISEL-NEXT: fcvtl v0.2d, v0.2s
114+
; GISEL-NEXT: fcvtl2 v0.2d, v0.4s
119115
; GISEL-NEXT: ret
120116
%ext = shufflevector <16 x i8> %x, <16 x i8> undef, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
121117
%bc2 = bitcast <8 x i8> %ext to <2 x float>
@@ -131,8 +127,7 @@ define <4 x float> @test_vcvt_high_v1i64_f16_bitcast(<2 x i64> %x) nounwind read
131127
;
132128
; GISEL-LABEL: test_vcvt_high_v1i64_f16_bitcast:
133129
; GISEL: // %bb.0:
134-
; GISEL-NEXT: mov d0, v0[1]
135-
; GISEL-NEXT: fcvtl v0.4s, v0.4h
130+
; GISEL-NEXT: fcvtl2 v0.4s, v0.8h
136131
; GISEL-NEXT: ret
137132
%ext = shufflevector <2 x i64> %x, <2 x i64> undef, <1 x i32> <i32 1>
138133
%bc2 = bitcast <1 x i64> %ext to <4 x half>
@@ -148,8 +143,7 @@ define <4 x float> @test_vcvt_high_v2i32_f16_bitcast(<4 x i32> %x) nounwind read
148143
;
149144
; GISEL-LABEL: test_vcvt_high_v2i32_f16_bitcast:
150145
; GISEL: // %bb.0:
151-
; GISEL-NEXT: mov d0, v0[1]
152-
; GISEL-NEXT: fcvtl v0.4s, v0.4h
146+
; GISEL-NEXT: fcvtl2 v0.4s, v0.8h
153147
; GISEL-NEXT: ret
154148
%ext = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3>
155149
%bc2 = bitcast <2 x i32> %ext to <4 x half>
@@ -181,8 +175,7 @@ define <4 x float> @test_vcvt_high_v8i8_f16_bitcast(<16 x i8> %x) nounwind readn
181175
;
182176
; GISEL-LABEL: test_vcvt_high_v8i8_f16_bitcast:
183177
; GISEL: // %bb.0:
184-
; GISEL-NEXT: mov d0, v0[1]
185-
; GISEL-NEXT: fcvtl v0.4s, v0.4h
178+
; GISEL-NEXT: fcvtl2 v0.4s, v0.8h
186179
; GISEL-NEXT: ret
187180
%ext = shufflevector <16 x i8> %x, <16 x i8> undef, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
188181
%bc2 = bitcast <8 x i8> %ext to <4 x half>

0 commit comments

Comments
 (0)