Skip to content

Commit ba471ba

Browse files
committed
Revert "[CodeGen][AArch64] Ensure isSExtCheaperThanZExt returns true for negative constants"
This reverts commit 31009f0. It seems to be causing SVE VLA buildbot failures and has introduced a genuine regression. Reverting for now.
1 parent fe17ce0 commit ba471ba

21 files changed

+80
-60
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,9 +2647,9 @@ class TargetLoweringBase {
26472647
getApproximateEVTForLLT(ToTy, DL, Ctx));
26482648
}
26492649

2650-
/// Return true if sign-extension of value \p V from FromTy to ToTy is
2651-
/// cheaper than zero-extension, where \p V can be SDValue() if unknown.
2652-
virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy, SDValue V) const {
2650+
/// Return true if sign-extension from FromTy to ToTy is cheaper than
2651+
/// zero-extension.
2652+
virtual bool isSExtCheaperThanZExt(EVT FromTy, EVT ToTy) const {
26532653
return false;
26542654
}
26552655

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7004,7 +7004,7 @@ bool CodeGenPrepare::optimizeSwitchInst(SwitchInst *SI) {
70047004
// matching the argument extension instead.
70057005
Instruction::CastOps ExtType = Instruction::ZExt;
70067006
// Some targets prefer SExt over ZExt.
7007-
if (TLI->isSExtCheaperThanZExt(OldVT, RegType, SDValue()))
7007+
if (TLI->isSExtCheaperThanZExt(OldVT, RegType))
70087008
ExtType = Instruction::SExt;
70097009

70107010
if (auto *Arg = dyn_cast<Argument>(Cond)) {

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ void DAGTypeLegalizer::PromoteSetCCOperands(SDValue &LHS, SDValue &RHS,
17041704
SDValue OpL = GetPromotedInteger(LHS);
17051705
SDValue OpR = GetPromotedInteger(RHS);
17061706

1707-
if (TLI.isSExtCheaperThanZExt(LHS.getValueType(), OpL.getValueType(), LHS)) {
1707+
if (TLI.isSExtCheaperThanZExt(LHS.getValueType(), OpL.getValueType())) {
17081708
// The target would prefer to promote the comparison operand with sign
17091709
// extension. Honor that unless the promoted values are already zero
17101710
// extended.

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
283283
EVT OldVT = Op.getValueType();
284284
SDLoc DL(Op);
285285
Op = GetPromotedInteger(Op);
286-
if (TLI.isSExtCheaperThanZExt(OldVT, Op.getValueType(), Op))
286+
if (TLI.isSExtCheaperThanZExt(OldVT, Op.getValueType()))
287287
return DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, Op.getValueType(), Op,
288288
DAG.getValueType(OldVT));
289289
return DAG.getZeroExtendInReg(Op, DL, OldVT);

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4767,7 +4767,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
47674767
C->isTargetOpcode(), C->isOpaque());
47684768
case ISD::ANY_EXTEND:
47694769
// Some targets like RISCV prefer to sign extend some types.
4770-
if (TLI->isSExtCheaperThanZExt(Operand.getValueType(), VT, Operand))
4770+
if (TLI->isSExtCheaperThanZExt(Operand.getValueType(), VT))
47714771
return getConstant(Val.sextOrTrunc(VT.getSizeInBits()), DL, VT,
47724772
C->isTargetOpcode(), C->isOpaque());
47734773
return getConstant(Val.zextOrTrunc(VT.getSizeInBits()), DL, VT,

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3844,7 +3844,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
38443844
} else if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG &&
38453845
(Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
38463846
!isSExtCheaperThanZExt(cast<VTSDNode>(N0.getOperand(1))->getVT(),
3847-
OpVT, N0.getOperand(1))) {
3847+
OpVT)) {
38483848
EVT ExtSrcTy = cast<VTSDNode>(N0.getOperand(1))->getVT();
38493849
unsigned ExtSrcTyBits = ExtSrcTy.getSizeInBits();
38503850
EVT ExtDstTy = N0.getValueType();

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,14 +1138,6 @@ class AArch64TargetLowering : public TargetLowering {
11381138

11391139
bool isConstantUnsignedBitfieldExtractLegal(unsigned Opc, LLT Ty1,
11401140
LLT Ty2) const override;
1141-
1142-
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT, SDValue V) const override {
1143-
if (!V)
1144-
return false;
1145-
if (ConstantSDNode *C = isConstOrConstSplat(V))
1146-
return C->getAPIntValue().isNegative();
1147-
return false;
1148-
}
11491141
};
11501142

11511143
namespace AArch64 {

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,7 @@ bool RISCVTargetLowering::isZExtFree(SDValue Val, EVT VT2) const {
11981198
return TargetLowering::isZExtFree(Val, VT2);
11991199
}
12001200

1201-
bool RISCVTargetLowering::isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT,
1202-
SDValue V) const {
1201+
bool RISCVTargetLowering::isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const {
12031202
return Subtarget.is64Bit() && SrcVT == MVT::i32 && DstVT == MVT::i64;
12041203
}
12051204

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class RISCVTargetLowering : public TargetLowering {
326326
bool isTruncateFree(Type *SrcTy, Type *DstTy) const override;
327327
bool isTruncateFree(EVT SrcVT, EVT DstVT) const override;
328328
bool isZExtFree(SDValue Val, EVT VT2) const override;
329-
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT, SDValue V) const override;
329+
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
330330
bool isCheapToSpeculateCttz() const override;
331331
bool isCheapToSpeculateCtlz() const override;
332332
bool hasAndNotCompare(SDValue Y) const override;

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ entry:
1414
ret <8 x i1> %Shuff
1515
}
1616

17+
; CHECK: lCPI1_0:
18+
; CHECK: .byte 0 ; 0x0
19+
; CHECK: .byte 0 ; 0x0
20+
; CHECK: .byte 0 ; 0x0
21+
; CHECK: .byte 0 ; 0x0
22+
; CHECK: .byte 1 ; 0x1
23+
; CHECK: .byte 0 ; 0x0
24+
; CHECK: .byte 0 ; 0x0
25+
; CHECK: .byte 0 ; 0x0
1726
; CHECK: test2
18-
; CHECK: movi d{{[0-9]+}}, #0x0000ff00000000
27+
; CHECK: adrp x[[REG2:[0-9]+]], lCPI1_0@PAGE
28+
; CHECK: ldr d[[REG1:[0-9]+]], [x[[REG2]], lCPI1_0@PAGEOFF]
1929
define <8 x i1>@test2() {
2030
bb:
2131
%Shuff = shufflevector <8 x i1> zeroinitializer,
@@ -26,7 +36,7 @@ bb:
2636
}
2737

2838
; CHECK: test3
29-
; CHECK: movi.2d v{{[0-9]+}}, #0x0000ff000000ff
39+
; CHECK: movi.4s v{{[0-9]+}}, #1
3040
define <16 x i1> @test3(i1* %ptr, i32 %v) {
3141
bb:
3242
%Shuff = shufflevector <16 x i1> <i1 0, i1 1, i1 1, i1 0, i1 0, i1 1, i1 0, i1 0, i1 0, i1 1, i1 1, i1 0, i1 0, i1 1, i1 0, i1 0>, <16 x i1> undef,
@@ -35,13 +45,11 @@ bb:
3545
i32 14, i32 0>
3646
ret <16 x i1> %Shuff
3747
}
38-
39-
4048
; CHECK: lCPI3_0:
4149
; CHECK: .byte 0 ; 0x0
4250
; CHECK: .byte 0 ; 0x0
4351
; CHECK: .byte 0 ; 0x0
44-
; CHECK: .byte 255 ; 0xff
52+
; CHECK: .byte 1 ; 0x1
4553
; CHECK: .byte 0 ; 0x0
4654
; CHECK: .byte 0 ; 0x0
4755
; CHECK: .byte 0 ; 0x0

0 commit comments

Comments
 (0)