Skip to content

Commit bf5f441

Browse files
authored
[DirectX] Add 32- and 64-bit 3-element vectors to DataLayout (#160955)
This explicitly adds two 3-element vectors to the DataLayout so that they'll be element-aligned. We need to do this more generally for vectors, but this unblocks some very common cases. Workaround for #123968
1 parent c87e0e8 commit bf5f441

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

clang/lib/Basic/Targets/DirectX.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
6464
NoAsmVariants = true;
6565
PlatformMinVersion = Triple.getOSVersion();
6666
PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
67+
// TODO: We need to align vectors on the element size generally, but for now
68+
// we hard code this for 3-element 32- and 64-bit vectors as a workaround.
69+
// See https://github.com/llvm/llvm-project/issues/123968
6770
resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
68-
"32-f64:64-n8:16:32:64");
71+
"32-f64:64-n8:16:32:64-v48:16:16-v96:32:32-v192:64:64");
6972
TheCXXABI.set(TargetCXXABI::GenericItanium);
7073
}
7174
bool useFP16ConversionIntrinsics() const override { return false; }

clang/test/CodeGenHLSL/basic-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-domain -emit-llvm -o - %s | FileCheck %s
77
// RUN: %clang -cc1 -triple dxil-pc-shadermodel6.0-geometry -emit-llvm -o - %s | FileCheck %s
88

9-
// CHECK: target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
9+
// CHECK: target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64-v48:16:16-v96:32:32-v192:64:64"
1010
// CHECK: target triple = "dxilv1.0-pc-shadermodel6.0-{{[a-z]+}}"

llvm/lib/TargetParser/TargetDataLayout.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,11 @@ std::string Triple::computeDataLayout(StringRef ABIName) const {
548548
case Triple::csky:
549549
return computeCSKYDataLayout(*this);
550550
case Triple::dxil:
551+
// TODO: We need to align vectors on the element size generally, but for now
552+
// we hard code this for 3-element 32- and 64-bit vectors as a workaround.
553+
// See https://github.com/llvm/llvm-project/issues/123968
551554
return "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-"
552-
"f32:32-f64:64-n8:16:32:64";
555+
"f32:32-f64:64-n8:16:32:64-v48:16:16-v96:32:32-v192:64:64";
553556
case Triple::hexagon:
554557
return "e-m:e-p:32:32:32-a:0-n16:32-"
555558
"i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"

llvm/test/CodeGen/DirectX/CBufferAccess/memcpy.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ entry:
7474
; CHECK: [[UPTO1:%.*]] = insertelement <3 x double> [[UPTO0]], double [[Y]], i32 1
7575
; CHECK: [[UPTO2:%.*]] = insertelement <3 x double> [[UPTO1]], double [[Z]], i32 2
7676
; CHECK: [[DEST:%.*]] = getelementptr inbounds i8, ptr [[A2_COPY:%.*]], i32 0
77-
; CHECK: store <3 x double> [[UPTO2]], ptr [[DEST]], align 32
77+
; CHECK: store <3 x double> [[UPTO2]], ptr [[DEST]], align 8
7878
; CHECK: [[LOAD:%.*]] = call { double, double } @llvm.dx.resource.load.cbufferrow.2.{{.*}}(target("dx.CBuffer", {{.*}})) [[CB]], i32 5)
7979
; CHECK: [[X:%.*]] = extractvalue { double, double } [[LOAD]], 0
8080
; CHECK: [[Y:%.*]] = extractvalue { double, double } [[LOAD]], 1
@@ -83,9 +83,9 @@ entry:
8383
; CHECK: [[UPTO0:%.*]] = insertelement <3 x double> poison, double [[X]], i32 0
8484
; CHECK: [[UPTO1:%.*]] = insertelement <3 x double> [[UPTO0]], double [[Y]], i32 1
8585
; CHECK: [[UPTO2:%.*]] = insertelement <3 x double> [[UPTO1]], double [[Z]], i32 2
86-
; CHECK: [[DEST:%.*]] = getelementptr inbounds i8, ptr [[A2_COPY]], i32 32
87-
; CHECK: store <3 x double> [[UPTO2]], ptr [[DEST]], align 32
88-
call void @llvm.memcpy.p0.p2.i32(ptr align 32 %a2.copy, ptr addrspace(2) align 32 @a2, i32 64, i1 false)
86+
; CHECK: [[DEST:%.*]] = getelementptr inbounds i8, ptr [[A2_COPY]], i32 24
87+
; CHECK: store <3 x double> [[UPTO2]], ptr [[DEST]], align 8
88+
call void @llvm.memcpy.p0.p2.i32(ptr align 32 %a2.copy, ptr addrspace(2) align 32 @a2, i32 48, i1 false)
8989

9090
; CHECK: [[CB:%.*]] = load target("dx.CBuffer", {{.*}})), ptr @CB.cb, align 4
9191
; CHECK: [[LOAD:%.*]] = call { half, half, half, half, half, half, half, half } @llvm.dx.resource.load.cbufferrow.8.{{.*}}(target("dx.CBuffer", {{.*}})) [[CB]], i32 7)

0 commit comments

Comments
 (0)