diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index bf7c0074a38f0..e1923a3441790 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -4433,23 +4433,13 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) { // ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits) Constant *C; if (match(NotVal, m_AShr(m_Constant(C), m_Value(Y))) && - match(C, m_Negative())) { - // We matched a negative constant, so propagating undef is unsafe. - // Clamp undef elements to -1. - Type *EltTy = Ty->getScalarType(); - C = Constant::replaceUndefsWith(C, ConstantInt::getAllOnesValue(EltTy)); + match(C, m_Negative())) return BinaryOperator::CreateLShr(ConstantExpr::getNot(C), Y); - } // ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits) if (match(NotVal, m_LShr(m_Constant(C), m_Value(Y))) && - match(C, m_NonNegative())) { - // We matched a non-negative constant, so propagating undef is unsafe. - // Clamp undef elements to 0. - Type *EltTy = Ty->getScalarType(); - C = Constant::replaceUndefsWith(C, ConstantInt::getNullValue(EltTy)); + match(C, m_NonNegative())) return BinaryOperator::CreateAShr(ConstantExpr::getNot(C), Y); - } // ~(X + C) --> ~C - X if (match(NotVal, m_Add(m_Value(X), m_ImmConstant(C)))) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 00fb1f7dd75b7..fdadf729fbd54 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -4322,25 +4322,6 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst::Predicate Pred, Value *Op0, if (!IsLowBitMask()) return nullptr; - // The mask value may be a vector constant that has undefined elements. But - // it may not be safe to propagate those undefs into the new compare, so - // replace those elements by copying an existing, defined, and safe scalar - // constant. - Type *OpTy = M->getType(); - auto *VecC = dyn_cast(M); - auto *OpVTy = dyn_cast(OpTy); - if (OpVTy && VecC && VecC->containsUndefOrPoisonElement()) { - Constant *SafeReplacementConstant = nullptr; - for (unsigned i = 0, e = OpVTy->getNumElements(); i != e; ++i) { - if (!isa(VecC->getAggregateElement(i))) { - SafeReplacementConstant = VecC->getAggregateElement(i); - break; - } - } - assert(SafeReplacementConstant && "Failed to find undef replacement"); - M = Constant::replaceUndefsWith(VecC, SafeReplacementConstant); - } - return IC.Builder.CreateICmp(DstPred, X, M); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 53478e07394b2..a0333b7db8f7a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -842,9 +842,6 @@ Instruction *InstCombinerImpl::visitFMul(BinaryOperator &I) { isKnownNeverNaN(&I, /*Depth=*/0, SQ.getWithInstruction(&I)))) { if (FPC->isNegative()) Op0 = Builder.CreateFNegFMF(Op0, &I); - Op1 = Constant::replaceUndefsWith( - cast(Op1), - ConstantFP::get(Op1->getType()->getScalarType(), *FPC)); CallInst *CopySign = Builder.CreateIntrinsic(Intrinsic::copysign, {I.getType()}, {Op1, Op0}, &I); return replaceInstUsesWith(I, CopySign); diff --git a/llvm/test/Transforms/InstCombine/binop-itofp.ll b/llvm/test/Transforms/InstCombine/binop-itofp.ll index 19f7ca9282f29..702bbbbf7d176 100644 --- a/llvm/test/Transforms/InstCombine/binop-itofp.ll +++ b/llvm/test/Transforms/InstCombine/binop-itofp.ll @@ -1070,7 +1070,7 @@ define <2 x float> @nonzero_check_on_constant_for_si_fmul_vec_w_poison(i1 %c, i1 ; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0 ; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer ; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float> -; CHECK-NEXT: [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> zeroinitializer, <2 x float> [[CONV1_I]]) +; CHECK-NEXT: [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> , <2 x float> [[CONV1_I]]) ; CHECK-NEXT: store i32 [[SEL]], ptr [[G_2345:%.*]], align 4 ; CHECK-NEXT: ret <2 x float> [[MUL3_I_I]] ; @@ -1090,9 +1090,9 @@ define <2 x float> @nonzero_check_on_constant_for_si_fmul_nz_vec_w_poison(i1 %c, ; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16 ; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0 ; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer -; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float> +; CHECK-NEXT: [[MUL3_I_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float> ; CHECK-NEXT: store i32 [[SEL]], ptr [[G_2345:%.*]], align 4 -; CHECK-NEXT: ret <2 x float> [[CONV1_I]] +; CHECK-NEXT: ret <2 x float> [[MUL3_I_I]] ; %sel = select i1 %c, i32 65529, i32 53264 %conv.i.s = trunc i32 %sel to i16 @@ -1112,7 +1112,7 @@ define <2 x float> @nonzero_check_on_constant_for_si_fmul_negz_vec_w_poison(i1 % ; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer ; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float> ; CHECK-NEXT: [[TMP1:%.*]] = fneg <2 x float> [[CONV1_I]] -; CHECK-NEXT: [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> zeroinitializer, <2 x float> [[TMP1]]) +; CHECK-NEXT: [[MUL3_I_I:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> , <2 x float> [[TMP1]]) ; CHECK-NEXT: store i32 [[SEL]], ptr [[G_2345:%.*]], align 4 ; CHECK-NEXT: ret <2 x float> [[MUL3_I_I]] ; diff --git a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll index 95e6d5ac6a5f8..9b28129dd9e17 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll @@ -81,7 +81,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) { define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) { ; CHECK-LABEL: @p3_vec_splat_poison( -; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], +; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %tmp0 = and <3 x i8> %x, @@ -91,7 +91,7 @@ define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) { define <3 x i1> @p3_vec_nonsplat_poison(<3 x i8> %x) { ; CHECK-LABEL: @p3_vec_nonsplat_poison( -; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], +; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %tmp0 = and <3 x i8> %x, diff --git a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sgt-to-icmp-sgt.ll b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sgt-to-icmp-sgt.ll index f1333fed2c517..d1dd411ee86b3 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sgt-to-icmp-sgt.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sgt-to-icmp-sgt.ll @@ -75,7 +75,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase() { define <3 x i1> @p3_vec_splat_poison() { ; CHECK-LABEL: @p3_vec_splat_poison( ; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8() -; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X]], +; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %x = call <3 x i8> @gen3x8() @@ -87,7 +87,7 @@ define <3 x i1> @p3_vec_splat_poison() { define <3 x i1> @p3_vec_nonsplat_poison() { ; CHECK-LABEL: @p3_vec_nonsplat_poison( ; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8() -; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X]], +; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %x = call <3 x i8> @gen3x8() diff --git a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll index be6e3d0306bcd..8415204a4915a 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll @@ -60,7 +60,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase(<2 x i8> %x) { define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) { ; CHECK-LABEL: @p3_vec_splat_poison( -; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X:%.*]], +; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X:%.*]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %tmp0 = and <3 x i8> %x, @@ -70,7 +70,7 @@ define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) { define <3 x i1> @p3_vec_nonsplat_poison(<3 x i8> %x) { ; CHECK-LABEL: @p3_vec_nonsplat_poison( -; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X:%.*]], +; CHECK-NEXT: [[RET:%.*]] = icmp sgt <3 x i8> [[X:%.*]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %tmp0 = and <3 x i8> %x, diff --git a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ugt-to-icmp-ugt.ll b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ugt-to-icmp-ugt.ll index 6f6ba95a81c76..e8781407cb647 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ugt-to-icmp-ugt.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ugt-to-icmp-ugt.ll @@ -98,7 +98,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase1() { define <3 x i1> @p3_vec_splat_poison() { ; CHECK-LABEL: @p3_vec_splat_poison( ; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8() -; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X]], +; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %x = call <3 x i8> @gen3x8() @@ -110,7 +110,7 @@ define <3 x i1> @p3_vec_splat_poison() { define <3 x i1> @p3_vec_nonsplat_poison() { ; CHECK-LABEL: @p3_vec_nonsplat_poison( ; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8() -; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X]], +; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %x = call <3 x i8> @gen3x8() diff --git a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ult-to-icmp-ugt.ll b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ult-to-icmp-ugt.ll index 008fc6d2d6eda..70fb34f499289 100644 --- a/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ult-to-icmp-ugt.ll +++ b/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ult-to-icmp-ugt.ll @@ -82,7 +82,7 @@ define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) { define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) { ; CHECK-LABEL: @p3_vec_splat_poison( -; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], +; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %tmp0 = and <3 x i8> %x, @@ -92,7 +92,7 @@ define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) { define <3 x i1> @p3_vec_nonsplat_poison(<3 x i8> %x) { ; CHECK-LABEL: @p3_vec_nonsplat_poison( -; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], +; CHECK-NEXT: [[RET:%.*]] = icmp ugt <3 x i8> [[X:%.*]], ; CHECK-NEXT: ret <3 x i1> [[RET]] ; %tmp0 = and <3 x i8> %x, diff --git a/llvm/test/Transforms/InstCombine/fmul.ll b/llvm/test/Transforms/InstCombine/fmul.ll index e9c86a1270493..1526956c5b241 100644 --- a/llvm/test/Transforms/InstCombine/fmul.ll +++ b/llvm/test/Transforms/InstCombine/fmul.ll @@ -633,11 +633,11 @@ define float @log2half(float %x, float %y) { define float @log2half_commute(float %x1, float %y) { ; CHECK-LABEL: @log2half_commute( -; CHECK-NEXT: [[X1:%.*]] = fmul fast float [[X2:%.*]], 0x3FC24924A0000000 +; CHECK-NEXT: [[X:%.*]] = fmul fast float [[X1:%.*]], 0x3FC24924A0000000 ; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]]) -; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[X1]] -; CHECK-NEXT: [[TMP3:%.*]] = fsub fast float [[TMP2]], [[X1]] -; CHECK-NEXT: ret float [[TMP3]] +; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[X]] +; CHECK-NEXT: [[MUL:%.*]] = fsub fast float [[TMP2]], [[X]] +; CHECK-NEXT: ret float [[MUL]] ; %x = fdiv fast float %x1, 7.0 ; thwart complexity-based canonicalization %halfy = fmul fast float %y, 0.5 @@ -687,8 +687,8 @@ define float @fdiv_constant_numerator_fmul_fast(float %x) { define float @fdiv_constant_numerator_fmul_precdiv(float %x) { ; CHECK-LABEL: @fdiv_constant_numerator_fmul_precdiv( ; CHECK-NEXT: [[T1:%.*]] = fdiv float 2.000000e+03, [[X:%.*]] -; CHECK-NEXT: [[T4:%.*]] = fmul reassoc float [[T1]], 6.000000e+03 -; CHECK-NEXT: ret float [[T4]] +; CHECK-NEXT: [[T3:%.*]] = fmul reassoc float [[T1]], 6.000000e+03 +; CHECK-NEXT: ret float [[T3]] ; %t1 = fdiv float 2.0e+3, %x %t3 = fmul reassoc float %t1, 6.0e+3 @@ -1288,7 +1288,7 @@ define half @mul_zero_nnan(half %x) { define <2 x float> @mul_zero_nnan_vec_poison(<2 x float> %x) { ; CHECK-LABEL: @mul_zero_nnan_vec_poison( -; CHECK-NEXT: [[R:%.*]] = call nnan <2 x float> @llvm.copysign.v2f32(<2 x float> zeroinitializer, <2 x float> [[X:%.*]]) +; CHECK-NEXT: [[R:%.*]] = call nnan <2 x float> @llvm.copysign.v2f32(<2 x float> , <2 x float> [[X:%.*]]) ; CHECK-NEXT: ret <2 x float> [[R]] ; %r = fmul nnan <2 x float> %x, @@ -1389,7 +1389,7 @@ define <3 x float> @mul_neg_zero_nnan_ninf_vec(<3 x float> nofpclass(inf nan) %a ; CHECK-LABEL: @mul_neg_zero_nnan_ninf_vec( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TMP0:%.*]] = fneg <3 x float> [[A:%.*]] -; CHECK-NEXT: [[RET:%.*]] = call <3 x float> @llvm.copysign.v3f32(<3 x float> zeroinitializer, <3 x float> [[TMP0]]) +; CHECK-NEXT: [[RET:%.*]] = call <3 x float> @llvm.copysign.v3f32(<3 x float> , <3 x float> [[TMP0]]) ; CHECK-NEXT: ret <3 x float> [[RET]] ; entry: diff --git a/llvm/test/Transforms/InstCombine/vector-xor.ll b/llvm/test/Transforms/InstCombine/vector-xor.ll index ee593b5d15e8e..5c96f1a691ed0 100644 --- a/llvm/test/Transforms/InstCombine/vector-xor.ll +++ b/llvm/test/Transforms/InstCombine/vector-xor.ll @@ -140,7 +140,7 @@ define <4 x i32> @test_v4i32_not_ashr_negative_const(<4 x i32> %a0) { define <4 x i32> @test_v4i32_not_ashr_negative_const_poison(<4 x i32> %a0) { ; CHECK-LABEL: @test_v4i32_not_ashr_negative_const_poison( -; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> , [[A0:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> , [[A0:%.*]] ; CHECK-NEXT: ret <4 x i32> [[TMP1]] ; %1 = ashr <4 x i32> , %a0 @@ -172,7 +172,7 @@ define <4 x i32> @test_v4i32_not_lshr_nonnegative_const(<4 x i32> %a0) { define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_poison(<4 x i32> %a0) { ; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const_poison( -; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> , [[A0:%.*]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> , [[A0:%.*]] ; CHECK-NEXT: ret <4 x i32> [[TMP1]] ; %1 = lshr <4 x i32> , %a0