From: Matt Arsenault Date: Thu, 7 Sep 2017 01:21:43 +0000 (+0000) Subject: InstSimplify: canonicalize is idempotent X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0de89287c6416b5ce76c6e719b421738cbb55cd;p=llvm InstSimplify: canonicalize is idempotent git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312685 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 94d71817049..ad3f9c39e48 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -4268,6 +4268,7 @@ static bool IsIdempotent(Intrinsic::ID ID) { case Intrinsic::rint: case Intrinsic::nearbyint: case Intrinsic::round: + case Intrinsic::canonicalize: return true; } } diff --git a/test/Transforms/InstSimplify/call.ll b/test/Transforms/InstSimplify/call.ll index c7d10e251b4..080d3ed2221 100644 --- a/test/Transforms/InstSimplify/call.ll +++ b/test/Transforms/InstSimplify/call.ll @@ -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() {