OSDN Git Service

InstSimplify: canonicalize is idempotent
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 7 Sep 2017 01:21:43 +0000 (01:21 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 7 Sep 2017 01:21:43 +0000 (01:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312685 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/call.ll

index 94d7181..ad3f9c3 100644 (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;
   }
 }
index c7d10e2..080d3ed 100644 (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() {