Skip to content

Commit 396aa58

Browse files
authored
[ValueTracking] Use unionWith when calculating known bits for abs. (#155896)
We may have already gotten information from range metadata, don't overwrite it.
1 parent ff22071 commit 396aa58

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
18281828
case Intrinsic::abs: {
18291829
computeKnownBits(I->getOperand(0), DemandedElts, Known2, Q, Depth + 1);
18301830
bool IntMinIsPoison = match(II->getArgOperand(1), m_One());
1831-
Known = Known2.abs(IntMinIsPoison);
1831+
Known = Known.unionWith(Known2.abs(IntMinIsPoison));
18321832
break;
18331833
}
18341834
case Intrinsic::bitreverse:

llvm/test/Transforms/InstCombine/abs-intrinsic.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,3 +847,16 @@ cond.end:
847847
%r = phi i32 [ %0, %cond.true ], [ 0, %entry ]
848848
ret i32 %r
849849
}
850+
851+
; The AND should be removable based on range metadata. Make sure
852+
; computeKnownBits doesn't lose this.
853+
define i32 @abs_range_metadata(i32 %x) {
854+
; CHECK-LABEL: @abs_range_metadata(
855+
; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false), !range [[RNG0:![0-9]+]]
856+
; CHECK-NEXT: ret i32 [[B]]
857+
;
858+
%a = call i32 @llvm.abs.i32(i32 %x, i1 false), !range !1
859+
%b = and i32 %a, 15
860+
ret i32 %b
861+
}
862+
!1 = !{i32 0, i32 16}

0 commit comments

Comments
 (0)