File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -1467,7 +1467,28 @@ ConstantRange ConstantRange::binaryXor(const ConstantRange &Other) const {
1467
1467
if (isSingleElement () && getSingleElement ()->isAllOnes ())
1468
1468
return Other.binaryNot ();
1469
1469
1470
- return fromKnownBits (toKnownBits () ^ Other.toKnownBits (), /* IsSigned*/ false );
1470
+ KnownBits LHSKnown = toKnownBits ();
1471
+ KnownBits RHSKnown = Other.toKnownBits ();
1472
+ KnownBits Known = LHSKnown ^ RHSKnown;
1473
+ ConstantRange CR = fromKnownBits (Known, /* IsSigned*/ false );
1474
+ // Typically the following code doesn't improve the result if BW = 1.
1475
+ if (getBitWidth () == 1 )
1476
+ return CR;
1477
+
1478
+ // If LHS is known to be the subset of RHS, treat LHS ^ RHS as RHS -nuw/nsw
1479
+ // LHS. If RHS is known to be the subset of LHS, treat LHS ^ RHS as LHS
1480
+ // -nuw/nsw RHS.
1481
+ if (LHSKnown.getMaxValue ().isSubsetOf (RHSKnown.getMinValue ()))
1482
+ CR = CR.intersectWith (
1483
+ Other.subWithNoWrap (*this , OverflowingBinaryOperator::NoUnsignedWrap |
1484
+ OverflowingBinaryOperator::NoSignedWrap),
1485
+ PreferredRangeType::Unsigned);
1486
+ else if (RHSKnown.getMaxValue ().isSubsetOf (LHSKnown.getMinValue ()))
1487
+ CR = CR.intersectWith (
1488
+ subWithNoWrap (Other, OverflowingBinaryOperator::NoUnsignedWrap |
1489
+ OverflowingBinaryOperator::NoSignedWrap),
1490
+ PreferredRangeType::Unsigned);
1491
+ return CR;
1471
1492
}
1472
1493
1473
1494
ConstantRange
Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ define i1 @constant_range_xor(i64 %a) {
12
12
; CHECK: then:
13
13
; CHECK-NEXT: [[CTLZ:%.*]] = call i64 @llvm.ctlz.i64(i64 [[A]], i1 true)
14
14
; CHECK-NEXT: [[CONV:%.*]] = xor i64 [[CTLZ]], 63
15
- ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[CONV]], 13
16
- ; CHECK-NEXT: ret i1 [[CMP1]]
15
+ ; CHECK-NEXT: ret i1 false
17
16
; CHECK: else:
18
17
; CHECK-NEXT: ret i1 false
19
18
;
You can’t perform that action at this time.
0 commit comments