Skip to content

Commit 221d2d0

Browse files
[FIXES]
1 parent 61b2910 commit 221d2d0

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,25 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
139139
.clampScalar(0, s32, sXLen)
140140
.minScalarSameAs(1, 0);
141141

142-
auto &ExtActions =
143-
getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})
144-
.customIf(typeIsLegalBoolVec(1, BoolVecTys, ST))
145-
.legalIf(all(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
146-
typeIsLegalIntOrFPVec(1, IntOrFPVecTys, ST)))
147-
.maxScalar(0, sXLen);
148142
if (ST.is64Bit()) {
149-
ExtActions.legalFor({{sXLen, s32}});
143+
getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})
144+
.customIf(typeIsLegalBoolVec(1, BoolVecTys, ST))
145+
.legalIf(all(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
146+
typeIsLegalIntOrFPVec(1, IntOrFPVecTys, ST)))
147+
.legalFor({{sXLen, s32}})
148+
.maxScalar(0, sXLen);
150149

151150
getActionDefinitionsBuilder(G_SEXT_INREG)
152151
.customFor({sXLen})
153152
.maxScalar(0, sXLen)
154153
.lower();
155154
} else {
155+
getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})
156+
.customIf(typeIsLegalBoolVec(1, BoolVecTys, ST))
157+
.legalIf(all(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
158+
typeIsLegalIntOrFPVec(1, IntOrFPVecTys, ST)))
159+
.maxScalar(0, sXLen);
160+
156161
getActionDefinitionsBuilder(G_SEXT_INREG).maxScalar(0, sXLen).lower();
157162
}
158163

llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,16 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
290290

291291
switch (Opc) {
292292
case TargetOpcode::G_ADD:
293-
case TargetOpcode::G_SUB:
293+
case TargetOpcode::G_SUB: {
294+
if (MRI.getType(MI.getOperand(0).getReg()).isVector()) {
295+
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
296+
return getInstructionMapping(
297+
DefaultMappingID, /*Cost=*/1,
298+
getVRBValueMapping(Ty.getSizeInBits().getKnownMinValue()),
299+
NumOperands);
300+
}
301+
}
302+
LLVM_FALLTHROUGH;
294303
case TargetOpcode::G_ANYEXT:
295304
case TargetOpcode::G_SEXT:
296305
case TargetOpcode::G_ZEXT: {
@@ -496,9 +505,10 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
496505
getVRBValueMapping(DstTy.getSizeInBits().getKnownMinValue());
497506
OpdsMapping[2] = OpdsMapping[3] =
498507
getVRBValueMapping(SrcTy.getSizeInBits().getKnownMinValue());
508+
break;
499509
}
500-
break;
501510
}
511+
LLVM_FALLTHROUGH;
502512
case TargetOpcode::G_FCMP: {
503513
LLT Ty = MRI.getType(MI.getOperand(2).getReg());
504514

llvm/test/MachineVerifier/test_g_fcmp.mir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ body: |
3232
3333
; mismatched scalable element count
3434
; CHECK: Bad machine code: Generic vector icmp/fcmp must preserve number of
35-
%6:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
36-
%7:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
37-
%8:_(<vscale x 4 x s1>) = G_FCMP floatpred(oeq), %6, %7
35+
%9:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
36+
%10:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
37+
%11:_(<vscale x 4 x s1>) = G_FCMP floatpred(oeq), %9, %10
3838
3939
; mismatched scalar element type
4040
; CHECK: *** Bad machine code: Type mismatch in generic instruction ***
41-
%9:_(s32) = G_FCONSTANT float 0.0
42-
%10:_(s64) = G_FCONSTANT float 1.0
43-
%11:_(s1) = G_FCMP floatpred(oeq), %9, %10
41+
%12:_(s32) = G_FCONSTANT float 0.0
42+
%13:_(s64) = G_FCONSTANT float 1.0
43+
%14:_(s1) = G_FCMP floatpred(oeq), %12, %13
4444
4545
...

llvm/test/MachineVerifier/test_g_icmp.mir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ body: |
3232
3333
; mismatched scalable element count
3434
; CHECK: Bad machine code: Generic vector icmp/fcmp must preserve number of
35-
%6:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
36-
%7:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
37-
%8:_(<vscale x 4 x s1>) = G_ICMP intpred(eq), %6, %7
35+
%9:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
36+
%10:_(<vscale x 2 x s32>) = G_IMPLICIT_DEF
37+
%11:_(<vscale x 4 x s1>) = G_ICMP intpred(eq), %9, %10
3838
3939
; mismatched scalar element type
4040
; CHECK: *** Bad machine code: Type mismatch in generic instruction ***
41-
%9:_(s32) = G_CONSTANT i32 0
42-
%10:_(s64) = G_CONSTANT i32 1
43-
%11:_(s1) = G_ICMP intpred(eq), %9, %10
41+
%12:_(s32) = G_CONSTANT i32 0
42+
%13:_(s64) = G_CONSTANT i32 1
43+
%14:_(s1) = G_ICMP intpred(eq), %12, %13
4444
4545
...

0 commit comments

Comments
 (0)