This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] Preserve vec3 for HLSL.
ClosedPublic

Authored by python3kgae on Aug 30 2022, 12:36 AM.

Details

Summary

Preserve vec3 for HLSL by set -fpreserve-vec3-type.

Diff Detail

Event Timeline

python3kgae created this revision.Aug 30 2022, 12:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 12:36 AM
Herald added a subscriber: Anastasia. · View Herald Transcript
python3kgae requested review of this revision.Aug 30 2022, 12:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 12:36 AM
beanz added inline comments.Aug 30 2022, 11:19 AM
clang/lib/Driver/ToolChains/Clang.cpp
3524 ↗(On Diff #456559)

Preserving vec3 is required for HLSL correctness, this shouldn't be tied to the DXC driver mode. Instead, the option should be implied by the HLSL language mode. You should be able to add the following to the TableGen definition for the preserve-vec3-type flag:

ImpliedByAnyOf<[hlsl.KeyPath]>;

Switch to ImpliedByAnyOf.

beanz accepted this revision.Sep 9 2022, 10:53 AM

LGTM

This revision is now accepted and ready to land.Sep 9 2022, 10:53 AM
This revision was automatically updated to reflect the committed changes.
python3kgae marked an inline comment as done.
chapuni added a subscriber: chapuni.Sep 9 2022, 2:22 PM

The test fails for -Asserts.

clang/test/CodeGenHLSL/float3.hlsl
4

Also %a may be unnamed, like %0

python3kgae added inline comments.Sep 9 2022, 2:28 PM
clang/test/CodeGenHLSL/float3.hlsl
4

Thanks for pointing this out.
I'll fix it.

The test fails for -Asserts.

Fixed the %0 issue in https://github.com/llvm/llvm-project/commit/71fae33f5e7c1b11e32db695fd24dd50aead737c
It passed locally on build with -DLLVM_ENABLE_ASSERTIONS=ON

Is -DLLVM_ENABLE_ASSERTIONS=ON what you mean by -Asserts?

The fix looks good. Thanks.

Is -DLLVM_ENABLE_ASSERTIONS=ON what you mean by -Asserts?

Oh excuse me, "-Asserts" was an ancient term, "w/o assertsions" in the autoconf age.
An antonym was "+Asserts". it means LLVM_ENABLE_ASSERTIONS=ON

The fix looks good. Thanks.

Is -DLLVM_ENABLE_ASSERTIONS=ON what you mean by -Asserts?

Oh excuse me, "-Asserts" was an ancient term, "w/o assertsions" in the autoconf age.
An antonym was "+Asserts". it means LLVM_ENABLE_ASSERTIONS=ON

I see. I'll test LLVM_ENABLE_ASSERTIONS=OFF this time.

The fix looks good. Thanks.

Is -DLLVM_ENABLE_ASSERTIONS=ON what you mean by -Asserts?

Oh excuse me, "-Asserts" was an ancient term, "w/o assertsions" in the autoconf age.
An antonym was "+Asserts". it means LLVM_ENABLE_ASSERTIONS=ON

I see. I'll test LLVM_ENABLE_ASSERTIONS=OFF this time.

Confirmed pass with LLVM_ENABLE_ASSERTIONS=OFF

alexgatea reopened this revision.Sep 13 2022, 7:27 AM
alexgatea added a subscriber: alexgatea.

This test fails because the actual output has <3 x float>* rather than ptr. Could you please fix this test case?

This revision is now accepted and ready to land.Sep 13 2022, 7:27 AM

This test fails because the actual output has <3 x float>* rather than ptr. Could you please fix this test case?

Thanks for reporting the issue.
But I cannot repro the fail.
Do you mind sharing your cmake command?

Thanks for reporting the issue.
But I cannot repro the fail.
Do you mind sharing your cmake command?

Hmm, I'm just running the command in the test case:
clang --driver-mode=dxc -Tlib_6_7 -fcgl -Fo - clang/test/CodeGenHLSL/float3.hlsl | FileCheck clang/test/CodeGenHLSL/float3.hlsl

Thanks for reporting the issue.
But I cannot repro the fail.
Do you mind sharing your cmake command?

Hmm, I'm just running the command in the test case:
clang --driver-mode=dxc -Tlib_6_7 -fcgl -Fo - clang/test/CodeGenHLSL/float3.hlsl | FileCheck clang/test/CodeGenHLSL/float3.hlsl

This is the output I got with clang --driver-mode=dxc -Tlib_6_7 -fcgl -Fo - clang/test/CodeGenHLSL/float3.hlsl

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"
target triple = "dxil-unknown-shadermodel6.7-library"

; Function Attrs: noinline nounwind optnone
define noundef <3 x float> @"?foo@@YAT?$__vector@M$02@__clang@@T12@@Z"(<3 x float> noundef %a) #0 {
entry:
  %a.addr = alloca <3 x float>, align 16
  store <3 x float> %a, ptr %a.addr, align 16
  %0 = load <3 x float>, ptr %a.addr, align 16
  ret <3 x float> %0
}

attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="96" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }

!llvm.module.flags = !{!0, !1}
!dx.valver = !{!2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"frame-pointer", i32 2}
!2 = !{i32 1, i32 7}
!3 = !{!"clang version 16.0.0 (https://github.com/llvm/llvm-project c9d2b6b92d6c29d00f6adc0527cf2331dbaae31a)"}

Maybe you build clang with a different setting? What are the CMake options you're using?

Thanks for reporting the issue.
But I cannot repro the fail.
Do you mind sharing your cmake command?

Hmm, I'm just running the command in the test case:
clang --driver-mode=dxc -Tlib_6_7 -fcgl -Fo - clang/test/CodeGenHLSL/float3.hlsl | FileCheck clang/test/CodeGenHLSL/float3.hlsl

This is the output I got with clang --driver-mode=dxc -Tlib_6_7 -fcgl -Fo - clang/test/CodeGenHLSL/float3.hlsl

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"
target triple = "dxil-unknown-shadermodel6.7-library"

; Function Attrs: noinline nounwind optnone
define noundef <3 x float> @"?foo@@YAT?$__vector@M$02@__clang@@T12@@Z"(<3 x float> noundef %a) #0 {
entry:
  %a.addr = alloca <3 x float>, align 16
  store <3 x float> %a, ptr %a.addr, align 16
  %0 = load <3 x float>, ptr %a.addr, align 16
  ret <3 x float> %0
}

attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="96" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }

!llvm.module.flags = !{!0, !1}
!dx.valver = !{!2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"frame-pointer", i32 2}
!2 = !{i32 1, i32 7}
!3 = !{!"clang version 16.0.0 (https://github.com/llvm/llvm-project c9d2b6b92d6c29d00f6adc0527cf2331dbaae31a)"}

Maybe you build clang with a different setting? What are the CMake options you're using?

Sorry for the delay and thank you for verifying. It turns out this is not due to a problem with the test itself, but rather a local problem with my compiler. No revision is necessary here, my apologies.

python3kgae closed this revision.Sep 13 2022, 1:53 PM
tahonermann added inline comments.
clang/test/CodeGenHLSL/float3.hlsl
1

Does this need to use driver mode? That is odd for a code gen test.

python3kgae marked an inline comment as done.Sep 17 2022, 12:28 AM
python3kgae added inline comments.
clang/test/CodeGenHLSL/float3.hlsl
1