1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[ConstantRange][CVP] Make use of abs poison flag

Pass the abs poison flag to the underlying ConstantRange
implementation, allowing CVP to simplify based on it.

Importantly, this recognizes that abs with poison flag is actually
non-negative...
This commit is contained in:
Nikita Popov 2020-07-30 22:54:53 +02:00
parent 50a1ea2ba8
commit 3f67e02a40
2 changed files with 7 additions and 5 deletions

View File

@ -872,9 +872,12 @@ ConstantRange ConstantRange::intrinsic(Intrinsic::ID IntrinsicID,
return Ops[0].smin(Ops[1]);
case Intrinsic::smax:
return Ops[0].smax(Ops[1]);
case Intrinsic::abs:
// TODO: Make use of poison flag.
return Ops[0].abs();
case Intrinsic::abs: {
const APInt *IntMinIsPoison = Ops[1].getSingleElement();
assert(IntMinIsPoison && "Must be known (immarg)");
assert(IntMinIsPoison->getBitWidth() == 1 && "Must be boolean");
return Ops[0].abs(IntMinIsPoison->getBoolValue());
}
default:
assert(!isIntrinsicSupported(IntrinsicID) && "Shouldn't be supported");
llvm_unreachable("Unsupported intrinsic");

View File

@ -141,8 +141,7 @@ define void @test_abs3(i32 %x) {
; CHECK-NEXT: [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
; CHECK-NEXT: br label [[SPLIT:%.*]]
; CHECK: split:
; CHECK-NEXT: [[C1:%.*]] = icmp sge i32 [[A]], 0
; CHECK-NEXT: call void @use(i1 [[C1]])
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[C2:%.*]] = icmp sgt i32 [[A]], 0
; CHECK-NEXT: call void @use(i1 [[C2]])
; CHECK-NEXT: ret void