1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[ValueTracking] Compute known bits of min/max intrinsics

Implement known bits for the min/max intrinsics based on the
recently added KnownBits primitives.
This commit is contained in:
Nikita Popov 2020-09-08 21:06:59 +02:00
parent 577016c234
commit dca909c3db
2 changed files with 24 additions and 16 deletions

View File

@ -1739,6 +1739,26 @@ static void computeKnownBitsFromOperator(const Operator *I,
} }
break; break;
} }
case Intrinsic::umin:
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
Known = KnownBits::umin(Known, Known2);
break;
case Intrinsic::umax:
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
Known = KnownBits::umax(Known, Known2);
break;
case Intrinsic::smin:
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
Known = KnownBits::smin(Known, Known2);
break;
case Intrinsic::smax:
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
Known = KnownBits::smax(Known, Known2);
break;
case Intrinsic::x86_sse42_crc32_64_64: case Intrinsic::x86_sse42_crc32_64_64:
Known.Zero.setBitsFrom(32); Known.Zero.setBitsFrom(32);
break; break;

View File

@ -8,10 +8,7 @@ declare i8 @llvm.smax.i8(i8, i8)
define i8 @umin_known_bits(i8 %x, i8 %y) { define i8 @umin_known_bits(i8 %x, i8 %y) {
; CHECK-LABEL: @umin_known_bits( ; CHECK-LABEL: @umin_known_bits(
; CHECK-NEXT: [[X2:%.*]] = and i8 [[X:%.*]], 127 ; CHECK-NEXT: ret i8 0
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umin.i8(i8 [[X2]], i8 [[Y:%.*]])
; CHECK-NEXT: [[R:%.*]] = and i8 [[M]], -128
; CHECK-NEXT: ret i8 [[R]]
; ;
%x2 = and i8 %x, 127 %x2 = and i8 %x, 127
%m = call i8 @llvm.umin.i8(i8 %x2, i8 %y) %m = call i8 @llvm.umin.i8(i8 %x2, i8 %y)
@ -21,10 +18,7 @@ define i8 @umin_known_bits(i8 %x, i8 %y) {
define i8 @umax_known_bits(i8 %x, i8 %y) { define i8 @umax_known_bits(i8 %x, i8 %y) {
; CHECK-LABEL: @umax_known_bits( ; CHECK-LABEL: @umax_known_bits(
; CHECK-NEXT: [[X2:%.*]] = or i8 [[X:%.*]], -128 ; CHECK-NEXT: ret i8 -128
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X2]], i8 [[Y:%.*]])
; CHECK-NEXT: [[R:%.*]] = and i8 [[M]], -128
; CHECK-NEXT: ret i8 [[R]]
; ;
%x2 = or i8 %x, -128 %x2 = or i8 %x, -128
%m = call i8 @llvm.umax.i8(i8 %x2, i8 %y) %m = call i8 @llvm.umax.i8(i8 %x2, i8 %y)
@ -34,10 +28,7 @@ define i8 @umax_known_bits(i8 %x, i8 %y) {
define i8 @smin_known_bits(i8 %x, i8 %y) { define i8 @smin_known_bits(i8 %x, i8 %y) {
; CHECK-LABEL: @smin_known_bits( ; CHECK-LABEL: @smin_known_bits(
; CHECK-NEXT: [[X2:%.*]] = or i8 [[X:%.*]], -128 ; CHECK-NEXT: ret i8 -128
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smin.i8(i8 [[X2]], i8 [[Y:%.*]])
; CHECK-NEXT: [[R:%.*]] = and i8 [[M]], -128
; CHECK-NEXT: ret i8 [[R]]
; ;
%x2 = or i8 %x, -128 %x2 = or i8 %x, -128
%m = call i8 @llvm.smin.i8(i8 %x2, i8 %y) %m = call i8 @llvm.smin.i8(i8 %x2, i8 %y)
@ -47,10 +38,7 @@ define i8 @smin_known_bits(i8 %x, i8 %y) {
define i8 @smax_known_bits(i8 %x, i8 %y) { define i8 @smax_known_bits(i8 %x, i8 %y) {
; CHECK-LABEL: @smax_known_bits( ; CHECK-LABEL: @smax_known_bits(
; CHECK-NEXT: [[X2:%.*]] = and i8 [[X:%.*]], 127 ; CHECK-NEXT: ret i8 0
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.smax.i8(i8 [[X2]], i8 [[Y:%.*]])
; CHECK-NEXT: [[R:%.*]] = and i8 [[M]], -128
; CHECK-NEXT: ret i8 [[R]]
; ;
%x2 = and i8 %x, 127 %x2 = and i8 %x, 127
%m = call i8 @llvm.smax.i8(i8 %x2, i8 %y) %m = call i8 @llvm.smax.i8(i8 %x2, i8 %y)