[llvm] 15042f4 - [InstCombine] propagate FMF when reordering intrinsics and shuffles

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 09:10:56 PDT 2022


Author: Sanjay Patel
Date: 2022-05-04T12:10:38-04:00
New Revision: 15042f44a231fb41f3166ca338ec6250a411b3f1

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

LOG: [InstCombine] propagate FMF when reordering intrinsics and shuffles

This was missed when extending the fold to allow fma with
9c4770eaab9d95c

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/fma.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d3bd826c54f64..485372c8b2c0d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1120,8 +1120,9 @@ foldShuffledIntrinsicOperands(IntrinsicInst *II,
   }
 
   // intrinsic (shuf X, M), (shuf Y, M), ... --> shuf (intrinsic X, Y, ...), M
+  Instruction *FPI = isa<FPMathOperator>(II) ? II : nullptr;
   Value *NewIntrinsic =
-      Builder.CreateIntrinsic(II->getIntrinsicID(), X->getType(), NewArgs);
+      Builder.CreateIntrinsic(II->getIntrinsicID(), X->getType(), NewArgs, FPI);
   return new ShuffleVectorInst(NewIntrinsic, Mask);
 }
 

diff  --git a/llvm/test/Transforms/InstCombine/fma.ll b/llvm/test/Transforms/InstCombine/fma.ll
index 912c37a5d4551..82fffd16ef521 100644
--- a/llvm/test/Transforms/InstCombine/fma.ll
+++ b/llvm/test/Transforms/InstCombine/fma.ll
@@ -751,7 +751,7 @@ define <3 x float> @fma_unary_shuffle_ops_widening(<2 x float> %x, <2 x float> %
 ; CHECK-LABEL: @fma_unary_shuffle_ops_widening(
 ; CHECK-NEXT:    [[A:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> poison, <3 x i32> <i32 1, i32 0, i32 1>
 ; CHECK-NEXT:    call void @use_vec3(<3 x float> [[A]])
-; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x float> @llvm.fma.v2f32(<2 x float> [[X]], <2 x float> [[Y:%.*]], <2 x float> [[Z:%.*]])
+; CHECK-NEXT:    [[TMP1:%.*]] = call fast <2 x float> @llvm.fma.v2f32(<2 x float> [[X]], <2 x float> [[Y:%.*]], <2 x float> [[Z:%.*]])
 ; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> poison, <3 x i32> <i32 1, i32 0, i32 1>
 ; CHECK-NEXT:    ret <3 x float> [[R]]
 ;
@@ -767,7 +767,7 @@ define <2 x float> @fma_unary_shuffle_ops_narrowing(<3 x float> %x, <3 x float>
 ; CHECK-LABEL: @fma_unary_shuffle_ops_narrowing(
 ; CHECK-NEXT:    [[B:%.*]] = shufflevector <3 x float> [[Y:%.*]], <3 x float> poison, <2 x i32> <i32 1, i32 0>
 ; CHECK-NEXT:    call void @use_vec(<2 x float> [[B]])
-; CHECK-NEXT:    [[TMP1:%.*]] = call <3 x float> @llvm.fma.v3f32(<3 x float> [[X:%.*]], <3 x float> [[Y]], <3 x float> [[Z:%.*]])
+; CHECK-NEXT:    [[TMP1:%.*]] = call nnan nsz <3 x float> @llvm.fma.v3f32(<3 x float> [[X:%.*]], <3 x float> [[Y]], <3 x float> [[Z:%.*]])
 ; CHECK-NEXT:    [[R:%.*]] = shufflevector <3 x float> [[TMP1]], <3 x float> poison, <2 x i32> <i32 1, i32 0>
 ; CHECK-NEXT:    ret <2 x float> [[R]]
 ;


        


More information about the llvm-commits mailing list