[PATCH] D127188: [InstCombine] improve fold for icmp-ugt-ashr
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 7 19:18:01 PDT 2022
Chenbing.Zheng updated this revision to Diff 435026.
Chenbing.Zheng added a comment.
address comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127188/new/
https://reviews.llvm.org/D127188
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-shr.ll
Index: llvm/test/Transforms/InstCombine/icmp-shr.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp-shr.ll
+++ llvm/test/Transforms/InstCombine/icmp-shr.ll
@@ -594,13 +594,9 @@
ret i1 %r
}
-; negative test
-; TODO: This is a sign-bit test, but we don't recognize the pattern.
-
define i1 @ashr_ugt_3(i4 %x) {
; CHECK-LABEL: @ashr_ugt_3(
-; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1
-; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 3
+; CHECK-NEXT: [[R:%.*]] = icmp slt i4 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%s = ashr i4 %x, 1
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2255,8 +2255,11 @@
}
if (Pred == CmpInst::ICMP_UGT) {
// icmp ugt (ashr X, ShAmtC), C --> icmp ugt X, ((C + 1) << ShAmtC) - 1
+ // Note: 'ShiftedC + 1' as an signed number may overflow, so than 'ashr'
+ // can not get expect value.
APInt ShiftedC = (C + 1).shl(ShAmtVal) - 1;
- if ((ShiftedC + 1).ashr(ShAmtVal) == (C + 1))
+ if ((ShiftedC + 1).ashr(ShAmtVal) == (C + 1) ||
+ (C + 1).shl(ShAmtVal).isMinSignedValue())
return new ICmpInst(Pred, X, ConstantInt::get(ShrTy, ShiftedC));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127188.435026.patch
Type: text/x-patch
Size: 1429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220608/3a5468d8/attachment.bin>
More information about the llvm-commits
mailing list