Skip to content

Commit 3d22d1c

Browse files
committed
AMDGPU: Make ballot intrinsic propagate poison
1 parent aac10b7 commit 3d22d1c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
10491049
break;
10501050
}
10511051
case Intrinsic::amdgcn_ballot: {
1052-
if (auto *Src = dyn_cast<ConstantInt>(II.getArgOperand(0))) {
1052+
Value *Arg = II.getArgOperand(0);
1053+
if (isa<PoisonValue>(Arg))
1054+
return IC.replaceInstUsesWith(II, PoisonValue::get(II.getType()));
1055+
1056+
if (auto *Src = dyn_cast<ConstantInt>(Arg)) {
10531057
if (Src->isZero()) {
10541058
// amdgcn.ballot(i1 0) is zero.
10551059
return IC.replaceInstUsesWith(II, Constant::getNullValue(II.getType()));

llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,22 @@ define i32 @ballot_one_32() {
29522952
ret i32 %b
29532953
}
29542954

2955+
define i64 @ballot_poison_64() {
2956+
; CHECK-LABEL: @ballot_poison_64(
2957+
; CHECK-NEXT: ret i64 poison
2958+
;
2959+
%b = call i64 @llvm.amdgcn.ballot.i64(i1 poison)
2960+
ret i64 %b
2961+
}
2962+
2963+
define i32 @ballot_poison_32() {
2964+
; CHECK-LABEL: @ballot_poison_32(
2965+
; CHECK-NEXT: ret i32 poison
2966+
;
2967+
%b = call i32 @llvm.amdgcn.ballot.i32(i1 poison)
2968+
ret i32 %b
2969+
}
2970+
29552971
; --------------------------------------------------------------------
29562972
; llvm.amdgcn.wqm.vote
29572973
; --------------------------------------------------------------------

0 commit comments

Comments
 (0)