Skip to content

[DirectX] make firstbitlow intrinsic use first argument instead of return for overload type #145350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

farzonl
Copy link
Member

@farzonl farzonl commented Jun 23, 2025

fixes #144966
Easy fix just add dx_firstbitlow to DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg

…turn for overload type

fixes llvm#144966
Easy fix just add `dx_firstbitlow` to `DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg`
@farzonl farzonl changed the title [DirectX] make firstbitlow intrinsic use first argument instead of re… [DirectX] make firstbitlow intrinsic use first argument instead of return for overload type Jun 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-backend-directx

Author: Farzon Lotfi (farzonl)

Changes

…turn for overload type

fixes #144966
Easy fix just add dx_firstbitlow to DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg


Full diff: https://github.com/llvm/llvm-project/pull/145350.diff

2 Files Affected:

  • (modified) llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp (+1)
  • (modified) llvm/test/CodeGen/DirectX/firstbitlow.ll (+17-4)
diff --git a/llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp b/llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp
index e426c5249f930..84b2603b4c575 100644
--- a/llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp
+++ b/llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp
@@ -30,6 +30,7 @@ bool DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
   switch (ID) {
   case Intrinsic::dx_asdouble:
   case Intrinsic::dx_isinf:
+  case Intrinsic::dx_firstbitlow:
     return OpdIdx == 0;
   default:
     return OpdIdx == -1;
diff --git a/llvm/test/CodeGen/DirectX/firstbitlow.ll b/llvm/test/CodeGen/DirectX/firstbitlow.ll
index 884ec1164fc99..fe3786d3fbebf 100644
--- a/llvm/test/CodeGen/DirectX/firstbitlow.ll
+++ b/llvm/test/CodeGen/DirectX/firstbitlow.ll
@@ -41,7 +41,20 @@ entry:
   ret <4 x i32> %2
 }
 
-declare i32 @llvm.dx.firstbitlow.i16(i16)
-declare i32 @llvm.dx.firstbitlow.i32(i32)
-declare i32 @llvm.dx.firstbitlow.i64(i64)
-declare <4 x i32> @llvm.dx.firstbitlow.v4i32(<4 x i32>)
+define noundef <4 x i32> @test_firstbitlow_vec4_i16(<4 x i16> noundef %a)  {
+entry:
+  ; CHECK: [[ee0:%.*]] = extractelement <4 x i16> %a, i64 0
+  ; CHECK: [[ie0:%.*]] = call i32 @dx.op.unaryBits.i16(i32 32, i16 [[ee0]])
+  ; CHECK: [[ee1:%.*]] = extractelement <4 x i16> %a, i64 1
+  ; CHECK: [[ie1:%.*]] = call i32 @dx.op.unaryBits.i16(i32 32, i16 [[ee1]])
+  ; CHECK: [[ee2:%.*]] = extractelement <4 x i16> %a, i64 2
+  ; CHECK: [[ie2:%.*]] = call i32 @dx.op.unaryBits.i16(i32 32, i16 [[ee2]])
+  ; CHECK: [[ee3:%.*]] = extractelement <4 x i16> %a, i64 3
+  ; CHECK: [[ie3:%.*]] = call i32 @dx.op.unaryBits.i16(i32 32, i16 [[ee3]])
+  ; CHECK: insertelement <4 x i32> poison, i32 [[ie0]], i64 0
+  ; CHECK: insertelement <4 x i32> %{{.*}}, i32 [[ie1]], i64 1
+  ; CHECK: insertelement <4 x i32> %{{.*}}, i32 [[ie2]], i64 2
+  ; CHECK: insertelement <4 x i32> %{{.*}}, i32 [[ie3]], i64 3
+  %2 = call <4 x i32> @llvm.dx.firstbitlow.v4i16(<4 x i16> %a)
+  ret <4 x i32> %2
+}

@farzonl
Copy link
Member Author

farzonl commented Jun 23, 2025

Build failure is
LLVM :: CodeGen/DirectX/min_vec_size.ll
https://github.com/llvm/llvm-project/actions/runs/15829219011/job/44617332565

thats an existing test failure.

@farzonl farzonl self-assigned this Jun 23, 2025
@V-FEXrt
Copy link
Contributor

V-FEXrt commented Jun 23, 2025

Note: This change needs to me made for first bit high as well. I'll do that in a follow up

@farzonl farzonl merged commit 0f173a0 into llvm:main Jun 23, 2025
9 of 10 checks passed
Jaddyen pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 23, 2025
…turn for overload type (llvm#145350)

fixes llvm#144966
Easy fix just add `dx_firstbitlow` to
`DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg`
V-FEXrt added a commit that referenced this pull request Jun 24, 2025
…145401)

Sibling to #145350 part of
#144966

firstbituhigh and firstbitshigh should use the first arg for overloads
instead of the return type since the return is always i32
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 24, 2025
…rload type (#145401)

Sibling to llvm/llvm-project#145350 part of
llvm/llvm-project#144966

firstbituhigh and firstbitshigh should use the first arg for overloads
instead of the return type since the return is always i32
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
…lvm#145401)

Sibling to llvm#145350 part of
llvm#144966

firstbituhigh and firstbitshigh should use the first arg for overloads
instead of the return type since the return is always i32
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…turn for overload type (llvm#145350)

fixes llvm#144966
Easy fix just add `dx_firstbitlow` to
`DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg`
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…lvm#145401)

Sibling to llvm#145350 part of
llvm#144966

firstbituhigh and firstbitshigh should use the first arg for overloads
instead of the return type since the return is always i32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL] Scalarizer incorrectly changes i64 vector calls to i32 calls
5 participants