Skip to content

Commit 32ef1af

Browse files
committed
[InstCombine] Drop samesign flags in foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed
1 parent 05d929e commit 32ef1af

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,11 @@ static Value *foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(
464464
// ie. (B & E) != 0, then LHS is subsumed by RHS. For example.
465465
// (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).
466466
assert(IsSubSetOrEqual(BCst, DCst) && "Precondition due to above code");
467-
if ((*BCst & ECst) != 0)
467+
if ((*BCst & ECst) != 0) {
468+
// We can't guarantee that samesign hold after this fold.
469+
RHS->setSameSign(false);
468470
return RHS;
471+
}
469472
// Otherwise, LHS and RHS contradict and the whole expression becomes false
470473
// (or true if negated.) For example,
471474
// (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.

llvm/test/Transforms/InstCombine/icmp-logical.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ define i1 @pr120361(i8 %x, i8 %y) {
19151915
define i1 @pr120361_v2(i32 %x) {
19161916
; CHECK-LABEL: @pr120361_v2(
19171917
; CHECK-NEXT: [[AND2:%.*]] = and i32 [[X:%.*]], -113
1918-
; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign eq i32 [[AND2]], 15
1918+
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[AND2]], 15
19191919
; CHECK-NEXT: ret i1 [[CMP2]]
19201920
;
19211921
%and1 = and i32 %x, 15

0 commit comments

Comments
 (0)