[PATCH] D144777: [InstCombine] Fold signbit test of a pow2 or zero
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 07:01:14 PST 2023
spatel added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1835-1836
}
+ // icmp slt (and -X, X), 0 --> icmp eq (X, MinSignedC)
+ // icmp sgt (and -X, X), -1 --> icmp ne (X, MinSignedC)
+ if (match(And, m_c_And(m_Neg(m_Value(X)), m_Deferred(X)))) {
----------------
It could go either way, but I prefer "C"-style notation (consistent with the comment above) for its compactness:
// (X & -X) < 0 --> X == MinSignedC
// (X & -X) > -1 --> X != MinSignedC
================
Comment at: llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll:55
; icmp sgt (and X, -X), -1 --> icmp ne (X, MinSignC)
-define i1 @pow2_or_zero2(i8 %x) {
-; CHECK-LABEL: @pow2_or_zero2(
-; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X:%.*]]
-; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[NEG]], [[X]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[POW2_OR_ZERO]], -1
+define i1 @pow2_or_zero_is_negative2(i8 %x) {
+; CHECK-LABEL: @pow2_or_zero_is_negative2(
----------------
This is "is_not_negative"
================
Comment at: llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll:104
+
+define i1 @pow2_or_zero_is_negative3(i8 %x) {
+; CHECK-LABEL: @pow2_or_zero_is_negative3(
----------------
Let's not duplicate everything for unsigned predicates. It's sufficient to change one or two of the above tests to confirm that we handle the various forms of signbit tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144777/new/
https://reviews.llvm.org/D144777
More information about the llvm-commits
mailing list