[DemandedBits] Track demanded bits for clmul instrinsics - #202415
Merged
Conversation
|
@llvm/pr-subscribers-llvm-analysis Author: 8051Enthusiast ChangesSimilar to regular multiplication, carryless multiplication does not depend on bits in positions higher than the output bits. No alive2 proof since clmul is not supported, but the implementation is the same as for Instruction::mul. Full diff: https://github.com/llvm/llvm-project/pull/202415.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/DemandedBits.cpp b/llvm/lib/Analysis/DemandedBits.cpp
index e0881751aef7e..35de778d9f093 100644
--- a/llvm/lib/Analysis/DemandedBits.cpp
+++ b/llvm/lib/Analysis/DemandedBits.cpp
@@ -114,6 +114,11 @@ void DemandedBits::determineLiveOperandBits(
// the output.
AB = AOut.reverseBits();
break;
+ case Intrinsic::clmul:
+ // Output bits only depend on input bits with lower or
+ // equal bit index.
+ AB = APInt::getLowBitsSet(BitWidth, AOut.getActiveBits());
+ break;
case Intrinsic::ctlz:
if (OperandNo == 0) {
// We need some output bits, so we need all bits of the
diff --git a/llvm/test/Analysis/DemandedBits/intrinsics.ll b/llvm/test/Analysis/DemandedBits/intrinsics.ll
index 0421b23202a2c..225c7cd4feef9 100644
--- a/llvm/test/Analysis/DemandedBits/intrinsics.ll
+++ b/llvm/test/Analysis/DemandedBits/intrinsics.ll
@@ -109,3 +109,16 @@ define i33 @test_fshr_non_pow2_bitwidth(i33 %x, i33 %y, i33 %z) {
%r = and i33 %f, 65535
ret i33 %r
}
+
+; CHECK-LABEL: Printing analysis 'Demanded Bits Analysis' for function 'test_clmul':
+; CHECK-DAG: DemandedBits: 0xffff for %x2 = or i32 %x, 1
+; CHECK-DAG: DemandedBits: 0xffff for %y2 = or i32 %y, 1
+; CHECK-DAG: DemandedBits: 0xff00 for %z = call i32 @llvm.clmul.i32(i32 %x2, i32 %y2)
+; CHECK-DAG: DemandedBits: 0xffffffff for %r = and i32 %z, 65280
+define i32 @test_clmul(i32 %x, i32 %y) {
+ %x2 = or i32 %x, 1
+ %y2 = or i32 %y, 1
+ %z = call i32 @llvm.clmul.i32(i32 %x2, i32 %y2)
+ %r = and i32 %z, 65280
+ ret i32 %r
+}
|
Similar to regular multiplication, carryless multiplication does not depend on bits in positions higher than the output bits. No alive2 proof since clmul is not supported, but the implementation is the same as for Instruction::mul.
8051Enthusiast
force-pushed
the
clmul-demanded-bits
branch
from
July 3, 2026 22:19
af49d37 to
3040a0e
Compare
Contributor
Author
Member
|
The clmul support is available now (see AliveToolkit/alive2#1318). But it hasn't been deployed to alive2.llvm.org. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Similar to regular multiplication, carryless multiplication does not depend on bits in positions higher than the output bits.
No alive2 proof since clmul is not supported, but the implementation is the same as for Instruction::mul.