[PATCH] D129103: [InstCombine] [NFC] use C.isNegatedPowerOf2() instead of (~C + 1).isPowerOf2()
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 4 19:56:37 PDT 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: spatel, RKSimon, benshi001.
Chenbing.Zheng added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129103
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/lshr-and-negC-icmpeq-zero.ll
Index: llvm/test/Transforms/InstCombine/lshr-and-negC-icmpeq-zero.ll
===================================================================
--- llvm/test/Transforms/InstCombine/lshr-and-negC-icmpeq-zero.ll
+++ llvm/test/Transforms/InstCombine/lshr-and-negC-icmpeq-zero.ll
@@ -234,3 +234,18 @@
%r = icmp eq i32 %and, 1 ; should be comparing with 0
ret i1 %r
}
+
+; Not NegatedPowerOf2
+
+define i1 @scalar_i8_lshr_and_negC_eq_not_negatedPowerOf2(i8 %x, i8 %y) {
+; CHECK-LABEL: @scalar_i8_lshr_and_negC_eq_not_negatedPowerOf2(
+; CHECK-NEXT: [[TMP1:%.*]] = shl i8 -3, [[Y:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP2]], 0
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %lshr = lshr i8 %x, %y
+ %and = and i8 %lshr, 253 ; -3
+ %r = icmp eq i8 %and, 0
+ ret i1 %r
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1779,7 +1779,7 @@
// Restrict this fold only for single-use 'and' (PR10267).
// ((%x & C) == 0) --> %x u< (-C) iff (-C) is power of two.
- if ((~(*C2) + 1).isPowerOf2()) {
+ if (C2->isNegatedPowerOf2()) {
Constant *NegBOC =
ConstantExpr::getNeg(cast<Constant>(And->getOperand(1)));
auto NewPred = isICMP_NE ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129103.442168.patch
Type: text/x-patch
Size: 1484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/57ffe8a1/attachment.bin>
More information about the llvm-commits
mailing list