[all-commits] [llvm/llvm-project] cba9dc: [libc][nfc] Use common implementation of read_firs...
Jon Chesterfield via All-commits
all-commits at lists.llvm.org
Wed Mar 12 14:30:21 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: cba9dc6e9d0455a0c4897c9acf61961b448b9d60
https://github.com/llvm/llvm-project/commit/cba9dc6e9d0455a0c4897c9acf61961b448b9d60
Author: Jon Chesterfield <jonathanchesterfield at gmail.com>
Date: 2025-03-12 (Wed, 12 Mar 2025)
Changed paths:
M clang/lib/Headers/amdgpuintrin.h
M clang/lib/Headers/gpuintrin.h
M clang/lib/Headers/nvptxintrin.h
M clang/test/Headers/gpuintrin.c
Log Message:
-----------
[libc][nfc] Use common implementation of read_first_lane_u64 (#131027)
No codegen regression on either target. The two builtin_ffs implied on
nvptx CSE away.
```
define internal i64 @__gpu_read_first_lane_u64(i64 noundef %__lane_mask, i64 noundef %__x) #2 {
entry:
%shr = lshr i64 %__x, 32
%conv = trunc nuw i64 %shr to i32
%conv1 = trunc i64 %__x to i32
%conv2 = trunc i64 %__lane_mask to i32
%0 = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 %conv2, i1 true)
%iszero = icmp eq i32 %conv2, 0
%sub = select i1 %iszero, i32 -1, i32 %0
%1 = tail call i32 @llvm.nvvm.shfl.sync.idx.i32(i32 %conv2, i32 %conv, i32 %sub, i32 31)
%conv4 = sext i32 %1 to i64
%shl = shl nsw i64 %conv4, 32
%2 = tail call i32 @llvm.nvvm.shfl.sync.idx.i32(i32 %conv2, i32 %conv1, i32 %sub, i32 31)
%conv7 = zext i32 %2 to i64
%or = or disjoint i64 %shl, %conv7
ret i64 %or
}
; becomes
define internal i64 @__gpu_competing_read_first_lane_u64(i64 noundef %__lane_mask, i64 noundef %__x) #2 {
entry:
%shr = lshr i64 %__x, 32
%conv = trunc nuw i64 %shr to i32
%conv1 = trunc i64 %__x to i32
%conv.i = trunc i64 %__lane_mask to i32
%0 = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 %conv.i, i1 true)
%iszero = icmp eq i32 %conv.i, 0
%sub.i = select i1 %iszero, i32 -1, i32 %0
%1 = tail call i32 @llvm.nvvm.shfl.sync.idx.i32(i32 %conv.i, i32 %conv, i32 %sub.i, i32 31)
%conv4 = zext i32 %1 to i64
%shl = shl nuw i64 %conv4, 32
%2 = tail call i32 @llvm.nvvm.shfl.sync.idx.i32(i32 %conv.i, i32 %conv1, i32 %sub.i, i32 31)
%conv7 = zext i32 %2 to i64
%or = or disjoint i64 %shl, %conv7
ret i64 %or
}
```
The sext vs zext difference is vaguely interesting but since the bits
are immediately discarded in either case it make no odds. The amdgcn one
doesn't need CSE, the readfirstlane function is a single call to an
intrinsic.
Drive by fix to __gpu_match_all_u32, it was calling first_lane_u64 and
could use first_lane_u32 instead. Added the missing call to gpuintrin.c
test case and a stray missing static as well.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list