InstSimplify: canonicalize is idempotent

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312685 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault 2017-09-07 01:21:43 +00:00
parent d91746fb9e
commit e0de89287c
2 changed files with 10 additions and 2 deletions

View File

@ -4268,6 +4268,7 @@ static bool IsIdempotent(Intrinsic::ID ID) {
case Intrinsic::rint:
case Intrinsic::nearbyint:
case Intrinsic::round:
case Intrinsic::canonicalize:
return true;
}
}

View File

@ -242,6 +242,7 @@ declare float @llvm.ceil.f32(float) nounwind readnone
declare float @llvm.trunc.f32(float) nounwind readnone
declare float @llvm.rint.f32(float) nounwind readnone
declare float @llvm.nearbyint.f32(float) nounwind readnone
declare float @llvm.canonicalize.f32(float) nounwind readnone
; Test idempotent intrinsics
define float @test_idempotence(float %a) {
@ -252,12 +253,14 @@ define float @test_idempotence(float %a) {
; CHECK-NEXT: [[D0:%.*]] = call float @llvm.trunc.f32(float [[A]])
; CHECK-NEXT: [[E0:%.*]] = call float @llvm.rint.f32(float [[A]])
; CHECK-NEXT: [[F0:%.*]] = call float @llvm.nearbyint.f32(float [[A]])
; CHECK-NEXT: [[G0:%.*]] = call float @llvm.canonicalize.f32(float [[A]])
; CHECK-NEXT: [[R0:%.*]] = fadd float [[A0]], [[B0]]
; CHECK-NEXT: [[R1:%.*]] = fadd float [[R0]], [[C0]]
; CHECK-NEXT: [[R2:%.*]] = fadd float [[R1]], [[D0]]
; CHECK-NEXT: [[R3:%.*]] = fadd float [[R2]], [[E0]]
; CHECK-NEXT: [[R4:%.*]] = fadd float [[R3]], [[F0]]
; CHECK-NEXT: ret float [[R4]]
; CHECK-NEXT: [[R5:%.*]] = fadd float [[R4]], [[G0]]
; CHECK-NEXT: ret float [[R5]]
;
%a0 = call float @llvm.fabs.f32(float %a)
@ -278,13 +281,17 @@ define float @test_idempotence(float %a) {
%f0 = call float @llvm.nearbyint.f32(float %a)
%f1 = call float @llvm.nearbyint.f32(float %f0)
%g0 = call float @llvm.canonicalize.f32(float %a)
%g1 = call float @llvm.canonicalize.f32(float %g0)
%r0 = fadd float %a1, %b1
%r1 = fadd float %r0, %c1
%r2 = fadd float %r1, %d1
%r3 = fadd float %r2, %e1
%r4 = fadd float %r3, %f1
%r5 = fadd float %r4, %g1
ret float %r4
ret float %r5
}
define i8* @operator_new() {