Skip to content

Commit 9237eda

Browse files
committed
Revert "[AArch64][GlobalISel] Legalize bswap <2 x i16>"
This reverts commit 5cd63e9. https://bugs.llvm.org/show_bug.cgi?id=51707 The sequence feeding in/out of the rev32/ushr isn't quite right: _swap: ldr h0, [x0] ldr h1, [x0, rust-lang#2] - mov v0.h[1], v1.h[0] + mov v0.s[1], v1.s[0] rev32 v0.8b, v0.8b ushr v0.2s, v0.2s, rust-lang#16 - mov h1, v0.h[1] + mov s1, v0.s[1] str h0, [x0] str h1, [x0, rust-lang#2] ret
1 parent f7bf8a8 commit 9237eda

File tree

4 files changed

+3
-75
lines changed

4 files changed

+3
-75
lines changed

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

+1-44
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
110110
getActionDefinitionsBuilder(G_BSWAP)
111111
.legalFor({s32, s64, v4s32, v2s32, v2s64})
112112
.widenScalarToNextPow2(0)
113-
.clampScalar(0, s32, s64)
114-
.customIf(typeIs(0, v2s16)); // custom lower as G_REV32 + G_LSHR
113+
.clampScalar(0, s32, s64);
115114

116115
getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
117116
.legalFor({s32, s64, v2s32, v4s32, v4s16, v8s16, v16s8, v8s8})
@@ -791,8 +790,6 @@ bool AArch64LegalizerInfo::legalizeCustom(LegalizerHelper &Helper,
791790
case TargetOpcode::G_LOAD:
792791
case TargetOpcode::G_STORE:
793792
return legalizeLoadStore(MI, MRI, MIRBuilder, Observer);
794-
case TargetOpcode::G_BSWAP:
795-
return legalizeBSwap(MI, MRI, MIRBuilder);
796793
case TargetOpcode::G_SHL:
797794
case TargetOpcode::G_ASHR:
798795
case TargetOpcode::G_LSHR:
@@ -1047,46 +1044,6 @@ bool AArch64LegalizerInfo::legalizeLoadStore(
10471044
return true;
10481045
}
10491046

1050-
bool AArch64LegalizerInfo::legalizeBSwap(MachineInstr &MI,
1051-
MachineRegisterInfo &MRI,
1052-
MachineIRBuilder &MIRBuilder) const {
1053-
assert(MI.getOpcode() == TargetOpcode::G_BSWAP);
1054-
1055-
// The <2 x half> case needs special lowering because there isn't an
1056-
// instruction that does that directly. Instead, we widen to <8 x i8>
1057-
// and emit a G_REV32 followed by a G_LSHR knowing that instruction selection
1058-
// will later match them as:
1059-
//
1060-
// rev32.8b v0, v0
1061-
// ushr.2s v0, v0, #16
1062-
//
1063-
// We could emit those here directly, but it seems better to keep things as
1064-
// generic as possible through legalization, and avoid committing layering
1065-
// violations by legalizing & selecting here at the same time.
1066-
1067-
Register ValReg = MI.getOperand(1).getReg();
1068-
assert(LLT::fixed_vector(2, 16) == MRI.getType(ValReg));
1069-
const LLT v2s32 = LLT::fixed_vector(2, 32);
1070-
const LLT v8s8 = LLT::fixed_vector(8, 8);
1071-
const LLT s32 = LLT::scalar(32);
1072-
1073-
auto Undef = MIRBuilder.buildUndef(v8s8);
1074-
auto Insert =
1075-
MIRBuilder
1076-
.buildInstr(TargetOpcode::INSERT_SUBREG, {v8s8}, {Undef, ValReg})
1077-
.addImm(AArch64::ssub);
1078-
auto Rev32 = MIRBuilder.buildInstr(AArch64::G_REV32, {v8s8}, {Insert});
1079-
auto Bitcast = MIRBuilder.buildBitcast(v2s32, Rev32);
1080-
auto Amt = MIRBuilder.buildConstant(v2s32, 16);
1081-
auto UShr =
1082-
MIRBuilder.buildInstr(TargetOpcode::G_LSHR, {v2s32}, {Bitcast, Amt});
1083-
auto Zero = MIRBuilder.buildConstant(s32, 0);
1084-
auto Extract = MIRBuilder.buildExtractVectorElement(s32, UShr, Zero);
1085-
MIRBuilder.buildBitcast({MI.getOperand(0).getReg()}, Extract);
1086-
MI.eraseFromParent();
1087-
return true;
1088-
}
1089-
10901047
bool AArch64LegalizerInfo::legalizeVaArg(MachineInstr &MI,
10911048
MachineRegisterInfo &MRI,
10921049
MachineIRBuilder &MIRBuilder) const {

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.h

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class AArch64LegalizerInfo : public LegalizerInfo {
3535
MachineInstr &MI) const override;
3636

3737
private:
38-
bool legalizeBSwap(MachineInstr &MI, MachineRegisterInfo &MRI,
39-
MachineIRBuilder &MIRBuilder) const;
4038
bool legalizeVaArg(MachineInstr &MI, MachineRegisterInfo &MRI,
4139
MachineIRBuilder &MIRBuilder) const;
4240
bool legalizeLoadStore(MachineInstr &MI, MachineRegisterInfo &MRI,

llvm/test/CodeGen/AArch64/GlobalISel/legalize-bswap.mir

-27
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,6 @@ body: |
2525
RET_ReallyLR implicit $w0
2626
...
2727
---
28-
name: bswap_2xi16
29-
tracksRegLiveness: true
30-
body: |
31-
bb.1:
32-
liveins: $s0
33-
34-
; CHECK-LABEL: name: bswap_2xi16
35-
; CHECK: liveins: $s0
36-
; CHECK: [[COPY:%[0-9]+]]:_(<2 x s16>) = COPY $s0
37-
; CHECK: [[DEF:%[0-9]+]]:_(<8 x s8>) = G_IMPLICIT_DEF
38-
; CHECK: [[INSERT_SUBREG:%[0-9]+]]:_(<8 x s8>) = INSERT_SUBREG [[DEF]](<8 x s8>), [[COPY]](<2 x s16>), %subreg.ssub
39-
; CHECK: [[REV32_:%[0-9]+]]:_(<8 x s8>) = G_REV32 [[INSERT_SUBREG]]
40-
; CHECK: [[BITCAST:%[0-9]+]]:_(<2 x s32>) = G_BITCAST [[REV32_]](<8 x s8>)
41-
; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
42-
; CHECK: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[C]](s32), [[C]](s32)
43-
; CHECK: [[LSHR:%[0-9]+]]:_(<2 x s32>) = G_LSHR [[BITCAST]], [[BUILD_VECTOR]](<2 x s32>)
44-
; CHECK: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
45-
; CHECK: [[EVEC:%[0-9]+]]:_(s32) = G_EXTRACT_VECTOR_ELT [[LSHR]](<2 x s32>), [[C1]](s64)
46-
; CHECK: [[BITCAST1:%[0-9]+]]:_(<2 x s16>) = G_BITCAST [[EVEC]](s32)
47-
; CHECK: $s0 = COPY [[BITCAST1]](<2 x s16>)
48-
; CHECK: RET_ReallyLR
49-
%0:_(<2 x s16>) = COPY $s0
50-
%1:_(<2 x s16>) = G_BSWAP %0
51-
$s0 = COPY %1(<2 x s16>)
52-
RET_ReallyLR
53-
...
54-
---
5528
name: bswap_s32_legal
5629
tracksRegLiveness: true
5730
body: |

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@
564564
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
565565
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
566566
# DEBUG-NEXT: G_BSWAP (opcode {{[0-9]+}}): 1 type index, 0 imm indices
567-
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
568-
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
567+
# DEBUG-NEXT: .. the first uncovered type index: 1, OK
568+
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
569569
# DEBUG-NEXT: G_BITREVERSE (opcode {{[0-9]+}}): 1 type index, 0 imm indices
570570
# DEBUG-NEXT: .. the first uncovered type index: 1, OK
571571
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK

0 commit comments

Comments
 (0)