The pattern is frequent enough to have its own implementation, which is
both more explicit and (slightly) faster than the default idiom.
Also use it to implement a faster llvm::KnownBits::isConstant() that doesn't
rely on popcnt.
Paths
| Differential D136323
[ADT] Add APInt::isInvertOf AbandonedPublic Authored by serge-sans-paille on Oct 20 2022, 2:24 AM.
Details
Summary The pattern is frequent enough to have its own implementation, which is Also use it to implement a faster llvm::KnownBits::isConstant() that doesn't
Diff Detail
Event TimelineComment Actions Associated compile-time link: http://llvm-compile-time-tracker.com/compare.php?from=9708d88017d0c9adaea65a4f5a5b589b67f292e2&to=b92e36012cabfeafadc87e2e960779f01aadfdc2&stat=instructions Comment Actions Do we get a benefit is we change only the KnownBits::isConstant implementation to do Zero == ~One? In terms of readability, I find X == ~Y clearer than X.isInvertOf(Y), so I personally wouldn't do this without some noticeable impact. (Though I'm not particularly opposed either.)
Comment Actions
I've checked and the answer is no (at least as long as popcnt is available. (One | Zero).countPopulation() == getBitWidth() also is an alternative but it's not significantly faster.
ok, let's forget about it!
Revision Contents
Diff 469139 llvm/include/llvm/ADT/APInt.h
llvm/include/llvm/Support/KnownBits.h
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/Support/APInt.cpp
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/unittests/ADT/APIntTest.cpp
|
I think this will cause shift UB for zero-width APInts (yes, those are a thing now ...)