[llvm] 18b1e67 - [AMDGPU] Fix crash when dag-combining bitcast
Ruiling Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 19:24:34 PDT 2020
Author: Ruiling Song
Date: 2020-08-13T10:23:13+08:00
New Revision: 18b1e675232b44c905bce28211286f7df6434f27
URL: https://github.com/llvm/llvm-project/commit/18b1e675232b44c905bce28211286f7df6434f27
DIFF: https://github.com/llvm/llvm-project/commit/18b1e675232b44c905bce28211286f7df6434f27.diff
LOG: [AMDGPU] Fix crash when dag-combining bitcast
>From the code after the 'break', they are processing 64bit scalar and
vector bitcast. So I think the break-condition should be (cond1 || cond2)
This means we only execute following code if (64bit and dest-is-vector).
Also remove a previous fix which is not needed with this new fix.
(introduced in: 1349a04ef5f594dda705ec80474dda4837f26dba)
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D85804
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
llvm/test/CodeGen/AMDGPU/amdgcn.bitcast.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
index 776ca1094381..be8742c8dd47 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
@@ -3940,7 +3940,7 @@ SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
}
}
- if (DestVT.getSizeInBits() != 64 && !DestVT.isVector())
+ if (DestVT.getSizeInBits() != 64 || !DestVT.isVector())
break;
// Fold bitcasts of constants.
@@ -3949,14 +3949,12 @@ SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
// TODO: Generalize and move to DAGCombiner
SDValue Src = N->getOperand(0);
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Src)) {
- if (Src.getValueType() == MVT::i64) {
- SDLoc SL(N);
- uint64_t CVal = C->getZExtValue();
- SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, SL, MVT::v2i32,
- DAG.getConstant(Lo_32(CVal), SL, MVT::i32),
- DAG.getConstant(Hi_32(CVal), SL, MVT::i32));
- return DAG.getNode(ISD::BITCAST, SL, DestVT, BV);
- }
+ SDLoc SL(N);
+ uint64_t CVal = C->getZExtValue();
+ SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, SL, MVT::v2i32,
+ DAG.getConstant(Lo_32(CVal), SL, MVT::i32),
+ DAG.getConstant(Hi_32(CVal), SL, MVT::i32));
+ return DAG.getNode(ISD::BITCAST, SL, DestVT, BV);
}
if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Src)) {
diff --git a/llvm/test/CodeGen/AMDGPU/amdgcn.bitcast.ll b/llvm/test/CodeGen/AMDGPU/amdgcn.bitcast.ll
index ce1b7ef01f82..568e66b5756e 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgcn.bitcast.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgcn.bitcast.ll
@@ -298,3 +298,15 @@ define <2 x i64> @bitcast_v4f32_to_v2i64(<2 x i64> %arg) {
%div = udiv <2 x i64> %cast, %arg
ret <2 x i64> %div
}
+
+declare half @llvm.canonicalize.f16(half)
+
+; FUNC-LABEL: {{^}}bitcast_f32_to_v1i32:
+define amdgpu_kernel void @bitcast_f32_to_v1i32(i32 addrspace(1)* %out) {
+ %f16 = call arcp afn half @llvm.canonicalize.f16(half 0xH03F0)
+ %f32 = fpext half %f16 to float
+ %v = bitcast float %f32 to <1 x i32>
+ %v1 = extractelement <1 x i32> %v, i32 0
+ store i32 %v1, i32 addrspace(1)* %out
+ ret void
+}
More information about the llvm-commits
mailing list