[llvm] fde4ef1 - InstSimplify: Fold arithmetic_fence as idempotent

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 22:29:44 PST 2022


Author: Matt Arsenault
Date: 2022-11-15T22:29:34-08:00
New Revision: fde4ef19737e142fbe2fe2a3edd31963a254d3dd

URL: https://github.com/llvm/llvm-project/commit/fde4ef19737e142fbe2fe2a3edd31963a254d3dd
DIFF: https://github.com/llvm/llvm-project/commit/fde4ef19737e142fbe2fe2a3edd31963a254d3dd.diff

LOG: InstSimplify: Fold arithmetic_fence as idempotent

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/call.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 11ceff1a636d1..0f0c0bcb96e17 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5671,6 +5671,7 @@ static bool isIdempotent(Intrinsic::ID ID) {
   case Intrinsic::round:
   case Intrinsic::roundeven:
   case Intrinsic::canonicalize:
+  case Intrinsic::arithmetic_fence:
     return true;
   }
 }

diff  --git a/llvm/test/Transforms/InstSimplify/call.ll b/llvm/test/Transforms/InstSimplify/call.ll
index 2a775b1430f35..ffa4b8cb06596 100644
--- a/llvm/test/Transforms/InstSimplify/call.ll
+++ b/llvm/test/Transforms/InstSimplify/call.ll
@@ -309,6 +309,7 @@ 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
+declare float @llvm.arithmetic.fence.f32(float) nounwind readnone
 
 ; Test idempotent intrinsics
 define float @test_idempotence(float %a) {
@@ -320,13 +321,15 @@ define float @test_idempotence(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:    [[H0:%.*]] = call float @llvm.arithmetic.fence.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:    [[R5:%.*]] = fadd float [[R4]], [[G0]]
-; CHECK-NEXT:    ret float [[R5]]
+; CHECK-NEXT:    [[R6:%.*]] = fadd float [[R5]], [[H0]]
+; CHECK-NEXT:    ret float [[R6]]
 ;
 
   %a0 = call float @llvm.fabs.f32(float %a)
@@ -350,14 +353,18 @@ define float @test_idempotence(float %a) {
   %g0 = call float @llvm.canonicalize.f32(float %a)
   %g1 = call float @llvm.canonicalize.f32(float %g0)
 
+  %h0 = call float @llvm.arithmetic.fence.f32(float %a)
+  %h1 = call float @llvm.arithmetic.fence.f32(float %h0)
+
   %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
+  %r6 = fadd float %r5, %h1
 
-  ret float %r5
+  ret float %r6
 }
 
 define ptr @operator_new() {
@@ -1373,7 +1380,7 @@ declare float @fmaxf(float, float)
 
 define float @nobuiltin_fmax() {
 ; CHECK-LABEL: @nobuiltin_fmax(
-; CHECK-NEXT:    [[M:%.*]] = call float @fmaxf(float 0.000000e+00, float 1.000000e+00) #[[ATTR3:[0-9]+]]
+; CHECK-NEXT:    [[M:%.*]] = call float @fmaxf(float 0.000000e+00, float 1.000000e+00) #[[ATTR4:[0-9]+]]
 ; CHECK-NEXT:    [[R:%.*]] = call float @llvm.fabs.f32(float [[M]])
 ; CHECK-NEXT:    ret float [[R]]
 ;


        


More information about the llvm-commits mailing list