[llvm] 19850cc - Revert "[RISCV] Lower BUILD_VECTOR to RISCVISD::VID_VL if it is floating-point type."
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 23 18:44:06 PDT 2022
Author: Craig Topper
Date: 2022-09-23T18:41:41-07:00
New Revision: 19850cc2d8529df8982a2846583480582dc2ebe6
URL: https://github.com/llvm/llvm-project/commit/19850cc2d8529df8982a2846583480582dc2ebe6
DIFF: https://github.com/llvm/llvm-project/commit/19850cc2d8529df8982a2846583480582dc2ebe6.diff
LOG: Revert "[RISCV] Lower BUILD_VECTOR to RISCVISD::VID_VL if it is floating-point type."
This reverts commit dd53a0bb30413d26c3ab63a5c57c3cdf301be7a1.
We have seen crashes from this internally. Probably due to the use
of RoundingMode::Dynamic.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
Removed:
llvm/test/CodeGen/RISCV/rvv/vle_vid-vfcvt.ll
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 55d0fe9c03eb..f517e2dfce46 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -2056,7 +2056,8 @@ struct VIDSequence {
static Optional<VIDSequence> isSimpleVIDSequence(SDValue Op) {
unsigned NumElts = Op.getNumOperands();
assert(Op.getOpcode() == ISD::BUILD_VECTOR && "Unexpected BUILD_VECTOR");
- bool IsInteger = Op.getValueType().isInteger();
+ if (!Op.getValueType().isInteger())
+ return None;
Optional<unsigned> SeqStepDenom;
Optional<int64_t> SeqStepNum, SeqAddend;
@@ -2067,30 +2068,12 @@ static Optional<VIDSequence> isSimpleVIDSequence(SDValue Op) {
// when interpolating across them.
if (Op.getOperand(Idx).isUndef())
continue;
+ // The BUILD_VECTOR must be all constants.
+ if (!isa<ConstantSDNode>(Op.getOperand(Idx)))
+ return None;
- uint64_t Val;
- if (IsInteger) {
- // The BUILD_VECTOR must be all constants.
- if (!isa<ConstantSDNode>(Op.getOperand(Idx)))
- return None;
- Val = Op.getConstantOperandVal(Idx) &
- maskTrailingOnes<uint64_t>(EltSizeInBits);
- } else {
- // The BUILD_VECTOR must be all constants.
- if (!isa<ConstantFPSDNode>(Op.getOperand(Idx)))
- return None;
- const APFloat &APF =
- cast<ConstantFPSDNode>(Op.getOperand(Idx))->getValueAPF();
- APSInt ValInt(EltSizeInBits, !APF.isNegative());
- bool IsExact;
- // If it is out of signed integer range, it will return an invalid
- // operation.
- if ((APF.convertToInteger(ValInt, RoundingMode::Dynamic, &IsExact) ==
- APFloatBase::opInvalidOp) ||
- !IsExact)
- return None;
- Val = ValInt.extractBitsAsZExtValue(EltSizeInBits, 0);
- }
+ uint64_t Val = Op.getConstantOperandVal(Idx) &
+ maskTrailingOnes<uint64_t>(EltSizeInBits);
if (PrevElt) {
// Calculate the step since the last non-undef element, and ensure
@@ -2139,18 +2122,8 @@ static Optional<VIDSequence> isSimpleVIDSequence(SDValue Op) {
for (unsigned Idx = 0; Idx < NumElts; Idx++) {
if (Op.getOperand(Idx).isUndef())
continue;
- uint64_t Val;
- if (IsInteger) {
- Val = Op.getConstantOperandVal(Idx) &
- maskTrailingOnes<uint64_t>(EltSizeInBits);
- } else {
- const APFloat &APF =
- cast<ConstantFPSDNode>(Op.getOperand(Idx))->getValueAPF();
- APSInt ValInt(EltSizeInBits, !APF.isNegative());
- bool DontCare;
- APF.convertToInteger(ValInt, RoundingMode::Dynamic, &DontCare);
- Val = ValInt.extractBitsAsZExtValue(EltSizeInBits, 0);
- }
+ uint64_t Val = Op.getConstantOperandVal(Idx) &
+ maskTrailingOnes<uint64_t>(EltSizeInBits);
uint64_t ExpectedVal =
(int64_t)(Idx * (uint64_t)*SeqStepNum) / *SeqStepDenom;
int64_t Addend = SignExtend64(Val - ExpectedVal, EltSizeInBits);
@@ -2358,36 +2331,27 @@ static SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG,
(StepOpcode == ISD::SHL && isUInt<5>(SplatStepVal))) &&
isPowerOf2_32(StepDenominator) &&
(SplatStepVal >= 0 || StepDenominator == 1) && isInt<5>(Addend)) {
- MVT VIDVT =
- VT.isFloatingPoint() ? VT.changeVectorElementTypeToInteger() : VT;
- MVT VIDContainerVT =
- getContainerForFixedLengthVector(DAG, VIDVT, Subtarget);
- SDValue VID = DAG.getNode(RISCVISD::VID_VL, DL, VIDContainerVT, Mask, VL);
+ SDValue VID = DAG.getNode(RISCVISD::VID_VL, DL, ContainerVT, Mask, VL);
// Convert right out of the scalable type so we can use standard ISD
// nodes for the rest of the computation. If we used scalable types with
// these, we'd lose the fixed-length vector info and generate worse
// vsetvli code.
- VID = convertFromScalableVector(VIDVT, VID, DAG, Subtarget);
+ VID = convertFromScalableVector(VT, VID, DAG, Subtarget);
if ((StepOpcode == ISD::MUL && SplatStepVal != 1) ||
(StepOpcode == ISD::SHL && SplatStepVal != 0)) {
SDValue SplatStep = DAG.getSplatBuildVector(
- VIDVT, DL, DAG.getConstant(SplatStepVal, DL, XLenVT));
- VID = DAG.getNode(StepOpcode, DL, VIDVT, VID, SplatStep);
+ VT, DL, DAG.getConstant(SplatStepVal, DL, XLenVT));
+ VID = DAG.getNode(StepOpcode, DL, VT, VID, SplatStep);
}
if (StepDenominator != 1) {
SDValue SplatStep = DAG.getSplatBuildVector(
- VIDVT, DL, DAG.getConstant(Log2_64(StepDenominator), DL, XLenVT));
- VID = DAG.getNode(ISD::SRL, DL, VIDVT, VID, SplatStep);
+ VT, DL, DAG.getConstant(Log2_64(StepDenominator), DL, XLenVT));
+ VID = DAG.getNode(ISD::SRL, DL, VT, VID, SplatStep);
}
if (Addend != 0 || Negate) {
SDValue SplatAddend = DAG.getSplatBuildVector(
- VIDVT, DL, DAG.getConstant(Addend, DL, XLenVT));
- VID = DAG.getNode(Negate ? ISD::SUB : ISD::ADD, DL, VIDVT, SplatAddend,
- VID);
- }
- if (VT.isFloatingPoint()) {
- // TODO: Use vfwcvt to reduce register pressure.
- VID = DAG.getNode(ISD::SINT_TO_FP, DL, VT, VID);
+ VT, DL, DAG.getConstant(Addend, DL, XLenVT));
+ VID = DAG.getNode(Negate ? ISD::SUB : ISD::ADD, DL, VT, SplatAddend, VID);
}
return VID;
}
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
index 1bbc7f02ac6f..0e04fb314958 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
@@ -71,9 +71,12 @@ define <4 x float> @hang_when_merging_stores_after_legalization(<8 x float> %x,
define void @buildvec_dominant0_v2f32(<2 x float>* %x) {
; CHECK-LABEL: buildvec_dominant0_v2f32:
; CHECK: # %bb.0:
+; CHECK-NEXT: lui a1, %hi(.LCPI2_0)
+; CHECK-NEXT: addi a1, a1, %lo(.LCPI2_0)
; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, mu
-; CHECK-NEXT: vid.v v8
-; CHECK-NEXT: vfcvt.f.x.v v8, v8
+; CHECK-NEXT: vlse32.v v8, (a1), zero
+; CHECK-NEXT: vsetvli zero, zero, e32, mf2, tu, mu
+; CHECK-NEXT: vmv.s.x v8, zero
; CHECK-NEXT: vse32.v v8, (a0)
; CHECK-NEXT: ret
store <2 x float> <float 0.0, float 1.0>, <2 x float>* %x
@@ -86,10 +89,10 @@ define void @buildvec_dominant0_v2f32(<2 x float>* %x) {
define void @buildvec_dominant1_v2f32(<2 x float>* %x) {
; CHECK-LABEL: buildvec_dominant1_v2f32:
; CHECK: # %bb.0:
+; CHECK-NEXT: lui a1, %hi(.LCPI3_0)
+; CHECK-NEXT: addi a1, a1, %lo(.LCPI3_0)
; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, mu
-; CHECK-NEXT: vid.v v8
-; CHECK-NEXT: vadd.vi v8, v8, 1
-; CHECK-NEXT: vfcvt.f.x.v v8, v8
+; CHECK-NEXT: vle32.v v8, (a1)
; CHECK-NEXT: vse32.v v8, (a0)
; CHECK-NEXT: ret
store <2 x float> <float 1.0, float 2.0>, <2 x float>* %x
diff --git a/llvm/test/CodeGen/RISCV/rvv/vle_vid-vfcvt.ll b/llvm/test/CodeGen/RISCV/rvv/vle_vid-vfcvt.ll
deleted file mode 100644
index 2a50643bd03a..000000000000
--- a/llvm/test/CodeGen/RISCV/rvv/vle_vid-vfcvt.ll
+++ /dev/null
@@ -1,100 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -mtriple=riscv64 -mattr=+v -verify-machineinstrs | FileCheck %s
-
-define void @foo_1(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_1:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: lui a1, %hi(.LCPI0_0)
-; CHECK-NEXT: addi a1, a1, %lo(.LCPI0_0)
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vle32.v v8, (a1)
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float -2147483648.0, float -2147483520.0, float -2147483392.0, float -2147483264.0>, ptr %t, align 16
- ret void
-}
-
-define void @foo_2(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_2:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: lui a1, %hi(.LCPI1_0)
-; CHECK-NEXT: addi a1, a1, %lo(.LCPI1_0)
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vle32.v v8, (a1)
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float 2147483136.0, float 2147483264.0, float 2147483392.0, float 2147483520.0>, ptr %t, align 16
- ret void
-}
-
-define void @foo_3(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_3:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vid.v v8
-; CHECK-NEXT: vadd.vi v8, v8, -1
-; CHECK-NEXT: vfcvt.f.x.v v8, v8
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float -1.0, float 0.0, float 1.0, float 2.0>, ptr %t, align 16
- ret void
-}
-
-define void @foo_4(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_4:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vid.v v8
-; CHECK-NEXT: vsll.vi v8, v8, 10
-; CHECK-NEXT: vadd.vi v8, v8, -16
-; CHECK-NEXT: vfcvt.f.x.v v8, v8
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float -16.0, float 1008.0, float 2032.0, float 3056.0>, ptr %t, align 16
- ret void
-}
-
-define void @foo_5(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_5:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vid.v v8
-; CHECK-NEXT: vfcvt.f.x.v v8, v8
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float 0.0, float 1.0, float 2.0, float 3.0>, ptr %t, align 16
- ret void
-}
-
-define void @foo_6(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_6:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: lui a1, %hi(.LCPI5_0)
-; CHECK-NEXT: addi a1, a1, %lo(.LCPI5_0)
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vle32.v v8, (a1)
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float -0.0, float 1.0, float 2.0, float 3.0>, ptr %t, align 16
- ret void
-}
-
-define void @foo_7(ptr nocapture noundef writeonly %t) {
-; CHECK-LABEL: foo_7:
-; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: lui a1, %hi(.LCPI6_0)
-; CHECK-NEXT: addi a1, a1, %lo(.LCPI6_0)
-; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, mu
-; CHECK-NEXT: vle32.v v8, (a1)
-; CHECK-NEXT: vse32.v v8, (a0)
-; CHECK-NEXT: ret
-entry:
- store <4 x float> <float -3.0, float -2.0, float -1.0, float -0.0>, ptr %t, align 16
- ret void
-}
More information about the llvm-commits
mailing list