[llvm] [DirectX] Generalize DXIL integer legalization (PR #225233)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 19:15:48 PDT 2026


================
@@ -0,0 +1,172 @@
+; RUN: opt -S -passes='dxil-legalize' -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
+
+define i1 @preserve_i1(i32 %value) {
+; CHECK-LABEL: define i1 @preserve_i1(
+; CHECK: [[RESULT:%.*]] = trunc i32 %value to i1
+; CHECK: ret i1 [[RESULT]]
+  %result = trunc i32 %value to i1
+  ret i1 %result
+}
+
+define i1 @packed_v3i1(<3 x i1> %value) {
+; CHECK-LABEL: define i1 @packed_v3i1(
+; CHECK-NOT: {{(^| )i3( |$)}}
+; CHECK: [[E0:%.*]] = extractelement <3 x i1> %value, i64 0
+; CHECK: [[Z0:%.*]] = zext i1 [[E0]] to i32
+; CHECK: [[E1:%.*]] = extractelement <3 x i1> %value, i64 1
+; CHECK: [[Z1:%.*]] = zext i1 [[E1]] to i32
+; CHECK: [[S1:%.*]] = shl i32 [[Z1]], 1
+; CHECK: [[E2:%.*]] = extractelement <3 x i1> %value, i64 2
+; CHECK: [[Z2:%.*]] = zext i1 [[E2]] to i32
+; CHECK: [[S2:%.*]] = shl i32 [[Z2]], 2
+; CHECK: [[PACKED:%.*]] = or i32
+; CHECK: ret i1
+  %packed = bitcast <3 x i1> %value to i3
----------------
farzonl wrote:

Yes, I guess we should but please not this pr it is already long. This pr just packs vector elements into a scalar carrier; it does not unpack a scalar into vector elements, but I suspect many of the helpers I wrote should be reusable.  I can create an issue to track the work.

https://github.com/llvm/llvm-project/pull/225233


More information about the llvm-commits mailing list