[PATCH] D86843: [EarlyCSE] Equivalent SELECTs should hash equally
Bryan Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 30 11:15:41 PDT 2020
bryanpkc updated this revision to Diff 288862.
bryanpkc added a comment.
Fixed linter warning.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86843/new/
https://reviews.llvm.org/D86843
Files:
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/test/Transforms/EarlyCSE/commute.ll
Index: llvm/test/Transforms/EarlyCSE/commute.ll
===================================================================
--- llvm/test/Transforms/EarlyCSE/commute.ll
+++ llvm/test/Transforms/EarlyCSE/commute.ll
@@ -684,6 +684,25 @@
ret i32 %r
}
+; This test is a reproducer for a bug involving inverted min/max selects
+; hashing differently but comparing as equal. It exhibits such a pair of
+; values, and we run this test with -earlycse-debug-hash which would catch
+; the disagreement and fail if it regressed.
+define i32 @inverted_max(i32 %i) {
+; CHECK-LABEL: @inverted_max(
+; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 0, [[I:%.*]]
+; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP]], i32 [[I]], i32 0
+; CHECK-NEXT: [[CMPINV:%.*]] = icmp sgt i32 0, [[I:%.*]]
+; CHECK-NEXT: [[M2:%.*]] = select i1 [[CMPINV]], i32 0, i32 [[I]]
+; CHECK-NEXT: [[R:%.*]] = add i32 [[M1]], [[M2]]
+; CHECK-NEXT: ret i32 [[R]]
+ %cmp = icmp sle i32 0, %i
+ %m1 = select i1 %cmp, i32 %i, i32 0
+ %cmpinv = icmp sgt i32 0, %i
+ %m2 = select i1 %cmpinv, i32 0, i32 %i
+ %r = add i32 %m1, %m2
+ ret i32 %r
+}
; This test is a reproducer for a bug involving inverted min/max selects
; hashing differently but comparing as equal. It exhibits such a pair of
Index: llvm/lib/Transforms/Scalar/EarlyCSE.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -191,6 +191,19 @@
Pred = ICmpInst::getSwappedPredicate(Pred);
}
+ // Check for inverted variants of min/max by swapping operands.
+ switch (Pred) {
+ case CmpInst::ICMP_ULE:
+ case CmpInst::ICMP_UGE:
+ case CmpInst::ICMP_SLE:
+ case CmpInst::ICMP_SGE:
+ Pred = CmpInst::getInversePredicate(Pred);
+ std::swap(A, B);
+ break;
+ default:
+ break;
+ }
+
switch (Pred) {
case CmpInst::ICMP_UGT: Flavor = SPF_UMAX; break;
case CmpInst::ICMP_ULT: Flavor = SPF_UMIN; break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86843.288862.patch
Type: text/x-patch
Size: 1972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/e9ac8ce0/attachment.bin>
More information about the llvm-commits
mailing list