Skip to content

Commit a716459

Browse files
authored
AMDGPU: Make ballot intrinsic propagate poison (#131061)
1 parent 75349d7 commit a716459

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
@@ -1050,7 +1050,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
10501050
break;
10511051
}
10521052
case Intrinsic::amdgcn_ballot: {
1053-
if (auto *Src = dyn_cast<ConstantInt>(II.getArgOperand(0))) {
1053+
Value *Arg = II.getArgOperand(0);
1054+
if (isa<PoisonValue>(Arg))
1055+
return IC.replaceInstUsesWith(II, PoisonValue::get(II.getType()));
1056+
1057+
if (auto *Src = dyn_cast<ConstantInt>(Arg)) {
10541058
if (Src->isZero()) {
10551059
// amdgcn.ballot(i1 0) is zero.
10561060
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
@@ -2960,6 +2960,22 @@ define i32 @ballot_one_32() {
29602960
ret i32 %b
29612961
}
29622962

2963+
define i64 @ballot_poison_64() {
2964+
; CHECK-LABEL: @ballot_poison_64(
2965+
; CHECK-NEXT: ret i64 poison
2966+
;
2967+
%b = call i64 @llvm.amdgcn.ballot.i64(i1 poison)
2968+
ret i64 %b
2969+
}
2970+
2971+
define i32 @ballot_poison_32() {
2972+
; CHECK-LABEL: @ballot_poison_32(
2973+
; CHECK-NEXT: ret i32 poison
2974+
;
2975+
%b = call i32 @llvm.amdgcn.ballot.i32(i1 poison)
2976+
ret i32 %b
2977+
}
2978+
29632979
; --------------------------------------------------------------------
29642980
; llvm.amdgcn.wqm.vote
29652981
; --------------------------------------------------------------------

0 commit comments

Comments
 (0)