[all-commits] [llvm/llvm-project] 16d1a6: [DirectX] Fix HLSL bitshifts to leverage the OpenC...
Cooper Partin via All-commits
all-commits at lists.llvm.org
Thu Feb 8 09:50:34 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 16d1a6486c25769d264a6ddb70a48bbb1c23c077
https://github.com/llvm/llvm-project/commit/16d1a6486c25769d264a6ddb70a48bbb1c23c077
Author: Cooper Partin <coopp at microsoft.com>
Date: 2024-02-08 (Thu, 08 Feb 2024)
Changed paths:
M clang/lib/CodeGen/CGExprScalar.cpp
A clang/test/CodeGenHLSL/shift-mask.hlsl
Log Message:
-----------
[DirectX] Fix HLSL bitshifts to leverage the OpenCL pipeline for bitshifting (#81030)
Fixes #55106
In HLSL bit shifts are defined to shift by shift size % type size. This
contains the following changes:
HLSL codegen bit shifts will be emitted as x << (y & (sizeof(x) - 1) and
bitshift masking leverages the OpenCL pipeline for this.
Tests were also added to validate this behavior.
Before this change the following was being emitted:
; Function Attrs: noinline nounwind optnone
define noundef i32 @"?shl32@@YAHHH at Z"(i32 noundef %V, i32 noundef %S) #0
{
entry:
%S.addr = alloca i32, align 4
%V.addr = alloca i32, align 4
store i32 %S, ptr %S.addr, align 4
store i32 %V, ptr %V.addr, align 4
%0 = load i32, ptr %V.addr, align 4
%1 = load i32, ptr %S.addr, align 4
%shl = shl i32 %0, %1
ret i32 %shl
}
After this change:
; Function Attrs: noinline nounwind optnone
define noundef i32 @"?shl32@@YAHHH at Z"(i32 noundef %V, i32 noundef %S) #0
{
entry:
%S.addr = alloca i32, align 4
%V.addr = alloca i32, align 4
store i32 %S, ptr %S.addr, align 4
store i32 %V, ptr %V.addr, align 4
%0 = load i32, ptr %V.addr, align 4
%1 = load i32, ptr %S.addr, align 4
%shl.mask = and i32 %1, 31
%shl = shl i32 %0, %shl.mask
ret i32 %shl
}
---------
Co-authored-by: Cooper Partin <coopp at ntdev.microsoft.com>
More information about the All-commits
mailing list