[llvm] [GlobalISel] Add CTLZ known bits. (PR #86436)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 24 06:39:45 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: David Green (davemgreen)
<details>
<summary>Changes</summary>
Copied from SDAG.
---
Full diff: https://github.com/llvm/llvm-project/pull/86436.diff
3 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp (+11)
- (modified) llvm/test/CodeGen/AArch64/setcc_knownbits.ll (+1-3)
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz-zero-undef.mir (+1-3)
``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
index 2e2cc9a95bd95c..914022ab7301b1 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -589,6 +589,17 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
}
break;
}
+ case TargetOpcode::G_CTLZ:
+ case TargetOpcode::G_CTLZ_ZERO_UNDEF: {
+ KnownBits SrcOpKnown;
+ computeKnownBitsImpl(MI.getOperand(1).getReg(), SrcOpKnown, DemandedElts,
+ Depth + 1);
+ // If we have a known 1, its position is our upper bound.
+ unsigned PossibleLZ = SrcOpKnown.countMaxLeadingZeros();
+ unsigned LowBits = llvm::bit_width(PossibleLZ);
+ Known.Zero.setBitsFrom(LowBits);
+ break;
+ }
}
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
diff --git a/llvm/test/CodeGen/AArch64/setcc_knownbits.ll b/llvm/test/CodeGen/AArch64/setcc_knownbits.ll
index 6a337bf02e09b9..8be63b04d8ce58 100644
--- a/llvm/test/CodeGen/AArch64/setcc_knownbits.ll
+++ b/llvm/test/CodeGen/AArch64/setcc_knownbits.ll
@@ -68,9 +68,7 @@ define i1 @lshr_ctlz_undef_cmpeq_one_i64(i64 %in) {
; CHECK-GI-LABEL: lshr_ctlz_undef_cmpeq_one_i64:
; CHECK-GI: // %bb.0:
; CHECK-GI-NEXT: clz x8, x0
-; CHECK-GI-NEXT: lsr x8, x8, #6
-; CHECK-GI-NEXT: cmp x8, #1
-; CHECK-GI-NEXT: cset w0, eq
+; CHECK-GI-NEXT: lsr w0, w8, #6
; CHECK-GI-NEXT: ret
%ctlz = call i64 @llvm.ctlz.i64(i64 %in, i1 -1)
%lshr = lshr i64 %ctlz, 6
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz-zero-undef.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz-zero-undef.mir
index e9f8180aae66bb..fed277d7d10d08 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz-zero-undef.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-ctlz-zero-undef.mir
@@ -64,9 +64,7 @@ body: |
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $vgpr0
; CHECK-NEXT: [[CTLZ_ZERO_UNDEF:%[0-9]+]]:_(s32) = G_CTLZ_ZERO_UNDEF [[COPY]](s32)
- ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
- ; CHECK-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[CTLZ_ZERO_UNDEF]], [[C]]
- ; CHECK-NEXT: $vgpr0 = COPY [[AND]](s32)
+ ; CHECK-NEXT: $vgpr0 = COPY [[CTLZ_ZERO_UNDEF]](s32)
%0:_(s32) = COPY $vgpr0
%1:_(s16) = G_CTLZ_ZERO_UNDEF %0
%2:_(s32) = G_ZEXT %1
``````````
</details>
https://github.com/llvm/llvm-project/pull/86436
More information about the llvm-commits
mailing list