Skip to content

Commit 2ea572a

Browse files
committed
Merging r348181:
------------------------------------------------------------------------ r348181 | lebedevri | 2018-12-03 12:07:58 -0800 (Mon, 03 Dec 2018) | 8 lines [InstCombine] foldICmpWithLowBitMaskedVal(): disable 2 faulty folds. These two folds are invalid for this non-constant pattern when the mask ends up being all-ones: https://rise4fun.com/Alive/9au https://rise4fun.com/Alive/UcQM Fixes https://bugs.llvm.org/show_bug.cgi?id=39861 ------------------------------------------------------------------------ llvm-svn: 348528
1 parent a0f6a34 commit 2ea572a

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,12 +2924,16 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I,
29242924
// x & (-1 >> y) s>= x -> x s<= (-1 >> y)
29252925
if (X != I.getOperand(1)) // X must be on RHS of comparison!
29262926
return nullptr; // Ignore the other case.
2927+
if (!match(M, m_Constant())) // Can not do this fold with non-constant.
2928+
return nullptr;
29272929
DstPred = ICmpInst::Predicate::ICMP_SLE;
29282930
break;
29292931
case ICmpInst::Predicate::ICMP_SLT:
29302932
// x & (-1 >> y) s< x -> x s> (-1 >> y)
29312933
if (X != I.getOperand(1)) // X must be on RHS of comparison!
29322934
return nullptr; // Ignore the other case.
2935+
if (!match(M, m_Constant())) // Can not do this fold with non-constant.
2936+
return nullptr;
29332937
DstPred = ICmpInst::Predicate::ICMP_SGT;
29342938
break;
29352939
case ICmpInst::Predicate::ICMP_SLE:

llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ define i1 @p0(i8 %x) {
2626
define i1 @pv(i8 %x, i8 %y) {
2727
; CHECK-LABEL: @pv(
2828
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
29-
; CHECK-NEXT: [[TMP1:%.*]] = icmp sge i8 [[TMP0]], [[X:%.*]]
30-
; CHECK-NEXT: ret i1 [[TMP1]]
29+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
30+
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[TMP1]], [[X]]
31+
; CHECK-NEXT: ret i1 [[RET]]
3132
;
3233
%tmp0 = lshr i8 -1, %y
3334
%tmp1 = and i8 %tmp0, %x
@@ -120,8 +121,9 @@ define i1 @cv0(i8 %y) {
120121
; CHECK-LABEL: @cv0(
121122
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
122123
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
123-
; CHECK-NEXT: [[TMP1:%.*]] = icmp sle i8 [[X]], [[TMP0]]
124-
; CHECK-NEXT: ret i1 [[TMP1]]
124+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
125+
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[TMP1]], [[X]]
126+
; CHECK-NEXT: ret i1 [[RET]]
125127
;
126128
%x = call i8 @gen8()
127129
%tmp0 = lshr i8 -1, %y

llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ define i1 @p0(i8 %x) {
2626
define i1 @pv(i8 %x, i8 %y) {
2727
; CHECK-LABEL: @pv(
2828
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
29-
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[TMP0]], [[X:%.*]]
30-
; CHECK-NEXT: ret i1 [[TMP1]]
29+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
30+
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
31+
; CHECK-NEXT: ret i1 [[RET]]
3132
;
3233
%tmp0 = lshr i8 -1, %y
3334
%tmp1 = and i8 %tmp0, %x
@@ -120,8 +121,9 @@ define i1 @cv0(i8 %y) {
120121
; CHECK-LABEL: @cv0(
121122
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
122123
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
123-
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
124-
; CHECK-NEXT: ret i1 [[TMP1]]
124+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
125+
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
126+
; CHECK-NEXT: ret i1 [[RET]]
125127
;
126128
%x = call i8 @gen8()
127129
%tmp0 = lshr i8 -1, %y

0 commit comments

Comments
 (0)