[llvm] 40d772c - [InstCombine] add one-use check to prevent creating an instruction in shuffle-of-binop

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 16:24:43 PST 2023


Author: Sanjay Patel
Date: 2023-02-22T19:20:32-05:00
New Revision: 40d772c642f70736d935bff0420a9bd1c1f80ab6

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

LOG: [InstCombine] add one-use check to prevent creating an instruction in shuffle-of-binop

This fold was added with https://reviews.llvm.org/D135876 ,
but we missed the one-use check.

This might be the root cause for issue #60632.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
    llvm/test/Transforms/InstCombine/shuffle-binop.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 3ad6b87b7e46..ea9aba449c74 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2718,7 +2718,8 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
 // splatting the first element of the result of the BinOp
 Instruction *InstCombinerImpl::simplifyBinOpSplats(ShuffleVectorInst &SVI) {
   if (!match(SVI.getOperand(1), m_Undef()) ||
-      !match(SVI.getShuffleMask(), m_ZeroMask()))
+      !match(SVI.getShuffleMask(), m_ZeroMask()) ||
+      !SVI.getOperand(0)->hasOneUse())
     return nullptr;
 
   Value *Op0 = SVI.getOperand(0);

diff  --git a/llvm/test/Transforms/InstCombine/shuffle-binop.ll b/llvm/test/Transforms/InstCombine/shuffle-binop.ll
index 74aa70cc0bc7..b298471a9428 100644
--- a/llvm/test/Transforms/InstCombine/shuffle-binop.ll
+++ b/llvm/test/Transforms/InstCombine/shuffle-binop.ll
@@ -201,12 +201,13 @@ define <2 x double> @shuffle_op2_0th_element_mask(ptr %a, ptr %b) {
   ret <2 x double> %shuffle
 }
 
+; This should not create an extra binop.
+
 define <2 x i4> @splat_binop_splat_uses(<2 x i4> %x, <2 x i4> %y) {
 ; CHECK-LABEL: @splat_binop_splat_uses(
 ; CHECK-NEXT:    [[XSPLAT:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:    [[XY:%.*]] = mul <2 x i4> [[XSPLAT]], [[Y:%.*]]
-; CHECK-NEXT:    [[TMP1:%.*]] = mul <2 x i4> [[X]], [[Y]]
-; CHECK-NEXT:    [[MSPLAT:%.*]] = shufflevector <2 x i4> [[TMP1]], <2 x i4> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[MSPLAT:%.*]] = shufflevector <2 x i4> [[XY]], <2 x i4> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:    [[RES:%.*]] = add <2 x i4> [[XY]], [[MSPLAT]]
 ; CHECK-NEXT:    ret <2 x i4> [[RES]]
 ;


        


More information about the llvm-commits mailing list