diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index b577f69eeaba0..7e5fda229b858 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -160,10 +160,9 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V, // If the cast operand is a constant vector, perform the cast by // operating on each element. In the cast of bitcasts, the element // count may be mismatched; don't attempt to handle that here. - if ((isa(V) || isa(V)) && - DestTy->isVectorTy() && - cast(DestTy)->getNumElements() == - cast(V->getType())->getNumElements()) { + if (DestTy->isVectorTy() && V->getType()->isVectorTy() && + cast(DestTy)->getElementCount() == + cast(V->getType())->getElementCount()) { VectorType *DestVecTy = cast(DestTy); Type *DstEltTy = DestVecTy->getElementType(); // Fast path for splatted constants. @@ -174,6 +173,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V, return ConstantVector::getSplat( cast(DestTy)->getElementCount(), Res); } + if (isa(DestTy)) + return nullptr; SmallVector res; Type *Ty = IntegerType::get(V->getContext(), 32); for (unsigned i = 0, diff --git a/llvm/test/Analysis/ValueTracking/known-bits-from-operator-constexpr.ll b/llvm/test/Analysis/ValueTracking/known-bits-from-operator-constexpr.ll index e3e30e052ee58..4dd9106898390 100644 --- a/llvm/test/Analysis/ValueTracking/known-bits-from-operator-constexpr.ll +++ b/llvm/test/Analysis/ValueTracking/known-bits-from-operator-constexpr.ll @@ -7,7 +7,7 @@ @g = global [21 x i32] zeroinitializer define i32 @test1(i32 %a) { ; CHECK-LABEL: @test1( -; CHECK-NEXT: [[T:%.*]] = sub i32 [[A:%.*]], extractelement (<4 x i32> ptrtoint (<4 x ptr> getelementptr inbounds ([21 x i32], ptr @g, <4 x i32> zeroinitializer, <4 x i32> ) to <4 x i32>), i32 3) +; CHECK-NEXT: [[T:%.*]] = sub i32 [[A:%.*]], ptrtoint (ptr getelementptr inbounds ([21 x i32], ptr @g, i32 0, i32 17) to i32) ; CHECK-NEXT: ret i32 [[T]] ; %t = sub i32 %a, extractelement (<4 x i32> ptrtoint (<4 x ptr> getelementptr inbounds ([21 x i32], ptr @g, <4 x i32> zeroinitializer, <4 x i32> ) to <4 x i32>), i32 3) diff --git a/llvm/test/Transforms/InstCombine/addrspacecast.ll b/llvm/test/Transforms/InstCombine/addrspacecast.ll index 00df545064069..8f3270cd60609 100644 --- a/llvm/test/Transforms/InstCombine/addrspacecast.ll +++ b/llvm/test/Transforms/InstCombine/addrspacecast.ll @@ -191,7 +191,7 @@ define ptr addrspace(4) @constant_fold_undef() #0 { define <4 x ptr addrspace(4)> @constant_fold_null_vector() #0 { ; CHECK-LABEL: @constant_fold_null_vector( -; CHECK-NEXT: ret <4 x ptr addrspace(4)> addrspacecast (<4 x ptr addrspace(3)> zeroinitializer to <4 x ptr addrspace(4)>) +; CHECK-NEXT: ret <4 x ptr addrspace(4)> ; %cast = addrspacecast <4 x ptr addrspace(3)> zeroinitializer to <4 x ptr addrspace(4)> ret <4 x ptr addrspace(4)> %cast diff --git a/llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll b/llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll index 595486361d16e..0982ecfbd3ea3 100644 --- a/llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll +++ b/llvm/test/Transforms/InstCombine/scalable-const-fp-splat.ll @@ -17,8 +17,7 @@ define @shrink_splat_scalable_extend( % define @shrink_splat_scalable_extend_rhs_constexpr( %a) { ; CHECK-LABEL: define @shrink_splat_scalable_extend_rhs_constexpr( ; CHECK-SAME: [[A:%.*]]) { -; CHECK-NEXT: [[TMP1:%.*]] = fptrunc splat (double -1.000000e+00) to -; CHECK-NEXT: [[TMP3:%.*]] = fadd [[A]], [[TMP1]] +; CHECK-NEXT: [[TMP3:%.*]] = fadd [[A]], splat (float -1.000000e+00) ; CHECK-NEXT: ret [[TMP3]] ; %2 = fpext %a to diff --git a/llvm/test/Transforms/InstCombine/scalable-trunc.ll b/llvm/test/Transforms/InstCombine/scalable-trunc.ll index dcf4abe10425b..6272ccfe9cdbd 100644 --- a/llvm/test/Transforms/InstCombine/scalable-trunc.ll +++ b/llvm/test/Transforms/InstCombine/scalable-trunc.ll @@ -20,6 +20,21 @@ entry: ret void } +define @constant_splat_trunc() { +; CHECK-LABEL: @constant_splat_trunc( +; CHECK-NEXT: ret splat (i8 1) +; + %1 = trunc splat (i64 1) to + ret %1 +} + +define @constant_splat_trunc_constantexpr() { +; CHECK-LABEL: @constant_splat_trunc_constantexpr( +; CHECK-NEXT: ret splat (i8 1) +; + ret trunc ( splat (i64 1) to ) +} + declare void @llvm.aarch64.sve.st1.nxv2i32(, , ptr) declare @llvm.aarch64.sve.convert.from.svbool.nxv2i1() declare @llvm.aarch64.sve.ptrue.nxv16i1(i32 %pattern) diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll b/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll index 3e4504a166366..f42f4071ac239 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/cast-vector.ll @@ -8,7 +8,7 @@ define <2 x i16> @test1() { ; CHECK-LABEL: @test1( ; CHECK-NEXT: entry: -; CHECK-NEXT: ret <2 x i16> ptrtoint (<2 x ptr> getelementptr inbounds ([10 x i32], ptr null, <2 x i64> zeroinitializer, <2 x i64> ) to <2 x i16>) +; CHECK-NEXT: ret <2 x i16> ; entry: %gep = getelementptr inbounds [10 x i32], ptr null, i16 0, <2 x i16> @@ -23,7 +23,7 @@ entry: define <2 x i16> @test2() { ; CHECK-LABEL: @test2( ; CHECK-NEXT: entry: -; CHECK-NEXT: ret <2 x i16> ptrtoint (<2 x ptr> getelementptr (i32, ptr null, <2 x i64> ) to <2 x i16>) +; CHECK-NEXT: ret <2 x i16> ; entry: %gep = getelementptr i32, ptr null, <2 x i16> diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/vscale-inseltpoison.ll b/llvm/test/Transforms/InstSimplify/ConstProp/vscale-inseltpoison.ll index a38dfaf8f5819..edc1260eca821 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/vscale-inseltpoison.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/vscale-inseltpoison.ll @@ -208,7 +208,7 @@ define @shufflevector() { define @bitcast() { ; CHECK-LABEL: @bitcast( -; CHECK-NEXT: ret bitcast ( splat (i32 1) to ) +; CHECK-NEXT: ret splat (float 0x36A0000000000000) ; %i1 = insertelement poison, i32 1, i32 0 %i2 = shufflevector %i1, poison, zeroinitializer diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/vscale.ll b/llvm/test/Transforms/InstSimplify/ConstProp/vscale.ll index e24f57445a4d1..8ee6fa6e5f37f 100644 --- a/llvm/test/Transforms/InstSimplify/ConstProp/vscale.ll +++ b/llvm/test/Transforms/InstSimplify/ConstProp/vscale.ll @@ -208,7 +208,7 @@ define @shufflevector() { define @bitcast() { ; CHECK-LABEL: @bitcast( -; CHECK-NEXT: ret bitcast ( splat (i32 1) to ) +; CHECK-NEXT: ret splat (float 0x36A0000000000000) ; %i1 = insertelement undef, i32 1, i32 0 %i2 = shufflevector %i1, undef, zeroinitializer diff --git a/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll b/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll index 70ca39da95310..593f334abac1e 100644 --- a/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll +++ b/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll @@ -140,7 +140,7 @@ define @cmp_le_smax_always_true( %x) { define @bitcast() { ; CHECK-LABEL: @bitcast( -; CHECK-NEXT: ret bitcast ( splat (i32 1) to ) +; CHECK-NEXT: ret splat (float 0x36A0000000000000) ; %i1 = insertelement poison, i32 1, i32 0 %i2 = shufflevector %i1, poison, zeroinitializer diff --git a/llvm/test/Transforms/InstSimplify/vscale.ll b/llvm/test/Transforms/InstSimplify/vscale.ll index 47cd88f4d5e4a..c09a0c201d761 100644 --- a/llvm/test/Transforms/InstSimplify/vscale.ll +++ b/llvm/test/Transforms/InstSimplify/vscale.ll @@ -152,7 +152,7 @@ define @cmp_le_smax_always_true( %x) { define @bitcast() { ; CHECK-LABEL: @bitcast( -; CHECK-NEXT: ret bitcast ( splat (i32 1) to ) +; CHECK-NEXT: ret splat (float 0x36A0000000000000) ; %i1 = insertelement undef, i32 1, i32 0 %i2 = shufflevector %i1, undef, zeroinitializer diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/induction-costs-sve.ll b/llvm/test/Transforms/LoopVectorize/AArch64/induction-costs-sve.ll index d7b9d4eba2462..08fea4bfc9b2e 100644 --- a/llvm/test/Transforms/LoopVectorize/AArch64/induction-costs-sve.ll +++ b/llvm/test/Transforms/LoopVectorize/AArch64/induction-costs-sve.ll @@ -51,8 +51,8 @@ define void @iv_casts(ptr %dst, ptr %src, i32 %x, i64 %N) #0 { ; DEFAULT-NEXT: [[TMP31:%.*]] = zext [[WIDE_LOAD4]] to ; DEFAULT-NEXT: [[TMP32:%.*]] = or [[TMP28]], [[TMP30]] ; DEFAULT-NEXT: [[TMP33:%.*]] = or [[TMP29]], [[TMP31]] -; DEFAULT-NEXT: [[TMP34:%.*]] = lshr [[TMP32]], trunc ( splat (i32 1) to ) -; DEFAULT-NEXT: [[TMP35:%.*]] = lshr [[TMP33]], trunc ( splat (i32 1) to ) +; DEFAULT-NEXT: [[TMP34:%.*]] = lshr [[TMP32]], splat (i16 1) +; DEFAULT-NEXT: [[TMP35:%.*]] = lshr [[TMP33]], splat (i16 1) ; DEFAULT-NEXT: [[TMP36:%.*]] = trunc [[TMP34]] to ; DEFAULT-NEXT: [[TMP37:%.*]] = trunc [[TMP35]] to ; DEFAULT-NEXT: [[TMP38:%.*]] = getelementptr i8, ptr [[DST]], i64 [[INDEX]] @@ -131,7 +131,7 @@ define void @iv_casts(ptr %dst, ptr %src, i32 %x, i64 %N) #0 { ; PRED-NEXT: [[TMP22:%.*]] = mul [[TMP17]], [[TMP16]] ; PRED-NEXT: [[TMP24:%.*]] = zext [[WIDE_MASKED_LOAD]] to ; PRED-NEXT: [[TMP20:%.*]] = or [[TMP22]], [[TMP24]] -; PRED-NEXT: [[TMP21:%.*]] = lshr [[TMP20]], trunc ( splat (i32 1) to ) +; PRED-NEXT: [[TMP21:%.*]] = lshr [[TMP20]], splat (i16 1) ; PRED-NEXT: [[TMP23:%.*]] = trunc [[TMP21]] to ; PRED-NEXT: [[TMP26:%.*]] = getelementptr i8, ptr [[DST]], i64 [[INDEX]] ; PRED-NEXT: [[TMP27:%.*]] = getelementptr i8, ptr [[TMP26]], i32 0 diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll index 12347103f64d4..dc2e99d33c377 100644 --- a/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll +++ b/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll @@ -169,7 +169,7 @@ define void @truncate_to_i1_used_by_branch(i8 %x, ptr %dst) #0 { ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector [[BROADCAST_SPLATINSERT]], poison, zeroinitializer ; CHECK-NEXT: [[TMP6:%.*]] = trunc i32 [[N_VEC]] to i8 ; CHECK-NEXT: [[TMP7:%.*]] = trunc [[BROADCAST_SPLAT]] to -; CHECK-NEXT: [[TMP8:%.*]] = or trunc ( splat (i8 23) to ), [[TMP7]] +; CHECK-NEXT: [[TMP8:%.*]] = or splat (i1 true), [[TMP7]] ; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement poison, ptr [[DST]], i64 0 ; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector [[BROADCAST_SPLATINSERT1]], poison, zeroinitializer ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-evl-crash.ll b/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-evl-crash.ll index dc7dd2c388731..656ae1cc03a80 100644 --- a/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-evl-crash.ll +++ b/llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-evl-crash.ll @@ -30,7 +30,7 @@ define void @truncate_to_minimal_bitwidths_widen_cast_recipe(ptr %src) { ; CHECK-NEXT: [[VP_OP_LOAD:%.*]] = call @llvm.vp.load.nxv8i8.p0(ptr align 1 [[TMP6]], splat (i1 true), i32 [[TMP7]]) ; CHECK-NEXT: [[TMP8:%.*]] = zext [[VP_OP_LOAD]] to ; CHECK-NEXT: [[TMP12:%.*]] = mul zeroinitializer, [[TMP8]] -; CHECK-NEXT: [[TMP13:%.*]] = lshr [[TMP12]], trunc ( splat (i32 1) to ) +; CHECK-NEXT: [[TMP13:%.*]] = lshr [[TMP12]], splat (i16 1) ; CHECK-NEXT: [[TMP14:%.*]] = trunc [[TMP13]] to ; CHECK-NEXT: call void @llvm.vp.scatter.nxv8i8.nxv8p0( [[TMP14]], align 1 zeroinitializer, splat (i1 true), i32 [[TMP7]]) ; CHECK-NEXT: [[TMP9:%.*]] = zext i32 [[TMP7]] to i64 diff --git a/llvm/test/Transforms/MemCpyOpt/crash.ll b/llvm/test/Transforms/MemCpyOpt/crash.ll index 494140a6d9262..0a5e76d99caf4 100644 --- a/llvm/test/Transforms/MemCpyOpt/crash.ll +++ b/llvm/test/Transforms/MemCpyOpt/crash.ll @@ -85,7 +85,7 @@ define void @test2(i32 %cmd) nounwind { define void @inttoptr_constexpr_crash(ptr %p) { ; CHECK-LABEL: @inttoptr_constexpr_crash( -; CHECK-NEXT: store <1 x ptr> inttoptr (<1 x i16> bitcast (<2 x i8> to <1 x i16>) to <1 x ptr>), ptr [[P:%.*]], align 1 +; CHECK-NEXT: store <1 x ptr> bitcast (<2 x i8> to <1 x i16>), i32 0) to ptr)>, ptr [[P:%.*]], align 1 ; CHECK-NEXT: ret void ; store <1 x ptr> inttoptr (<1 x i16> bitcast (<2 x i8> to <1 x i16>) to <1 x ptr>), ptr %p, align 1 diff --git a/llvm/test/Transforms/VectorCombine/pr88796.ll b/llvm/test/Transforms/VectorCombine/pr88796.ll index 6f988922f2cc0..3ca0786a6e803 100644 --- a/llvm/test/Transforms/VectorCombine/pr88796.ll +++ b/llvm/test/Transforms/VectorCombine/pr88796.ll @@ -4,7 +4,7 @@ define i32 @test() { ; CHECK-LABEL: define i32 @test() { ; CHECK-NEXT: entry: -; CHECK-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.vector.reduce.and.nxv8i16( trunc ( splat (i32 268435456) to )) +; CHECK-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.vector.reduce.and.nxv8i16( zeroinitializer) ; CHECK-NEXT: ret i32 0 ; entry: