[llvm] 2ce48b2 - [ConstantFolding] Fix bitcasting vectors with non-integer ratios (#179640)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 06:48:44 PDT 2026
Author: Kacper Doga
Date: 2026-04-07T13:48:38Z
New Revision: 2ce48b2691a49e91dc8ecd6dfb7eeb533f77a5c1
URL: https://github.com/llvm/llvm-project/commit/2ce48b2691a49e91dc8ecd6dfb7eeb533f77a5c1
DIFF: https://github.com/llvm/llvm-project/commit/2ce48b2691a49e91dc8ecd6dfb7eeb533f77a5c1.diff
LOG: [ConstantFolding] Fix bitcasting vectors with non-integer ratios (#179640)
For both downcast and upcast this patch introduces support for
bitcasting vectors with non-integer ratios [1, 2]. Also this patch
increases the coherence between casts [3].
1. Fixes a crash on downcast where the ratio is not an integer (e.g., <3
x i32> to <4 x i24>). Previously this led to leading to an incorrect
number of result elements and subsequent crashes in RAUW.
Fixes #179626
2. Fixes a miscompilation on upcast where ratio is not an integer (e.g.,
<4 x i24> to <3 x i32>). Previously this led to wrong result.
Fixes #181195
3. Fix incoherent value emitting between down/up cast
a. When upcasting, emit Poison and Undef not only if the source vector
consists of only one of these values. (e.g., `bitcast <4 x i32> <i32
undef, i32 undef, i32 1, i32 undef> to <2 x i64>` returns `<2 x i64>
<i64 undef, i64 1>`
b. When downcasting, when SrcElt is Poison, handle it as Poison and not
Undef. (e.g., `bitcast <1 x i32> <i32 poison> to <2 x i16>` returns `<2
x i16> poison`
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
llvm/test/Transforms/InstCombine/cast.ll
llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll
llvm/test/Transforms/SCCP/bitcast-vector-refinement.l.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 3c64ad6f6b369..589d8e334b88d 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -213,84 +213,78 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
}
// Now we know that the input and output vectors are both integer vectors
- // of the same size, and that their #elements is not the same. Do the
- // conversion here, which depends on whether the input or output has
- // more elements.
+ // of the same size, and that their #elements is not the same.
+ // Use data buffer for easy non-integer element ratio vectors handling,
+ // For example: <4 x i24> to <3 x i32>.
bool isLittleEndian = DL.isLittleEndian();
-
+ unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits();
+ unsigned DstBitSize = DstEltTy->getPrimitiveSizeInBits();
SmallVector<Constant*, 32> Result;
- if (NumDstElt < NumSrcElt) {
- // Handle: bitcast (<4 x i32> <i32 0, i32 1, i32 2, i32 3> to <2 x i64>)
- Constant *Zero = Constant::getNullValue(DstEltTy);
- unsigned Ratio = NumSrcElt/NumDstElt;
- unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits();
- unsigned SrcElt = 0;
- for (unsigned i = 0; i != NumDstElt; ++i) {
- // Build each element of the result.
- Constant *Elt = Zero;
- unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize*(Ratio-1);
- for (unsigned j = 0; j != Ratio; ++j) {
- Constant *Src = C->getAggregateElement(SrcElt++);
- if (isa_and_nonnull<UndefValue>(Src))
- Src = Constant::getNullValue(
- cast<VectorType>(C->getType())->getElementType());
- else
- Src = dyn_cast_or_null<ConstantInt>(Src);
- if (!Src) // Reject constantexpr elements.
- return ConstantExpr::getBitCast(C, DestTy);
-
- // Zero extend the element to the right size.
- Src = ConstantFoldCastOperand(Instruction::ZExt, Src, Elt->getType(),
- DL);
- assert(Src && "Constant folding cannot fail on plain integers");
-
- // Shift it to the right place, depending on endianness.
- Src = ConstantFoldBinaryOpOperands(
- Instruction::Shl, Src, ConstantInt::get(Src->getType(), ShiftAmt),
- DL);
- assert(Src && "Constant folding cannot fail on plain integers");
-
- ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
-
- // Mix it in.
- Elt = ConstantFoldBinaryOpOperands(Instruction::Or, Elt, Src, DL);
- assert(Elt && "Constant folding cannot fail on plain integers");
+ unsigned SrcElt = 0;
+
+ APInt Buffer(2 * std::max(SrcBitSize, DstBitSize), 0);
+ APInt UndefMask(Buffer.getBitWidth(), 0);
+ APInt PoisonMask(Buffer.getBitWidth(), 0);
+ unsigned BufferBitSize = 0;
+
+ while (Result.size() != NumDstElt) {
+ // Load SrcElts into Buffer.
+ while (BufferBitSize < DstBitSize) {
+ Constant *Element = C->getAggregateElement(SrcElt++);
+ if (!Element) // Reject constantexpr elements
+ return ConstantExpr::getBitCast(C, DestTy);
+
+ // Shift Buffer & Masks to fit next SrcElt.
+ if (!isLittleEndian) {
+ Buffer <<= SrcBitSize;
+ UndefMask <<= SrcBitSize;
+ PoisonMask <<= SrcBitSize;
}
- Result.push_back(Elt);
- }
- return ConstantVector::get(Result);
- }
- // Handle: bitcast (<2 x i64> <i64 0, i64 1> to <4 x i32>)
- unsigned Ratio = NumDstElt/NumSrcElt;
- unsigned DstBitSize = DL.getTypeSizeInBits(DstEltTy);
-
- // Loop over each source value, expanding into multiple results.
- for (unsigned i = 0; i != NumSrcElt; ++i) {
- auto *Element = C->getAggregateElement(i);
-
- if (!Element) // Reject constantexpr elements.
- return ConstantExpr::getBitCast(C, DestTy);
+ APInt SrcValue;
+ unsigned BitPosition = isLittleEndian ? BufferBitSize : 0;
+ if (isa<UndefValue>(Element)) {
+ // Set masks fragments bits.
+ UndefMask.setBits(BitPosition, BitPosition + SrcBitSize);
+ if (isa<PoisonValue>(Element))
+ PoisonMask.setBits(BitPosition, BitPosition + SrcBitSize);
+ SrcValue = APInt::getZero(DstBitSize);
+ } else {
+ auto *Src = dyn_cast<ConstantInt>(Element);
+ if (!Src)
+ return ConstantExpr::getBitCast(C, DestTy);
+ SrcValue = Src->getValue();
+ }
- if (isa<UndefValue>(Element)) {
- // Correctly Propagate undef values.
- Result.append(Ratio, UndefValue::get(DstEltTy));
- continue;
+ // Insert src element bits into Buffer on correct position.
+ Buffer.insertBits(SrcValue, BitPosition);
+ BufferBitSize += SrcBitSize;
}
- auto *Src = dyn_cast<ConstantInt>(Element);
- if (!Src)
- return ConstantExpr::getBitCast(C, DestTy);
-
- unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize*(Ratio-1);
- for (unsigned j = 0; j != Ratio; ++j) {
- // Shift the piece of the value into the right place, depending on
- // endianness.
- APInt Elt = Src->getValue().lshr(ShiftAmt);
- ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
+ // Create DstElts from Buffer.
+ while (BufferBitSize >= DstBitSize) {
+ unsigned ShiftAmt = isLittleEndian ? 0 : BufferBitSize - DstBitSize;
+ // Emit undef/poison, if all undef mask fragment bits are set.
+ if (UndefMask.extractBits(DstBitSize, ShiftAmt).isAllOnes()) {
+ // Push poison, if any bit in poison mask fragment is set.
+ if (!PoisonMask.extractBits(DstBitSize, ShiftAmt).isZero()) {
+ Result.push_back(PoisonValue::get(DstEltTy));
+ } else {
+ Result.push_back(UndefValue::get(DstEltTy));
+ }
+ } else {
+ // Create and push DstElt.
+ APInt Elt = Buffer.extractBits(DstBitSize, ShiftAmt);
+ Result.push_back(ConstantInt::get(DstEltTy, Elt));
+ }
- // Truncate and remember this piece.
- Result.push_back(ConstantInt::get(DstEltTy, Elt.trunc(DstBitSize)));
+ // Shift unused Buffer fragment to lower bits.
+ if (isLittleEndian) {
+ Buffer.lshrInPlace(DstBitSize);
+ UndefMask.lshrInPlace(DstBitSize);
+ PoisonMask.lshrInPlace(DstBitSize);
+ }
+ BufferBitSize -= DstBitSize;
}
}
diff --git a/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll b/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
index 7462e311b02ad..8b92eb4c59cc5 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
@@ -138,7 +138,7 @@ define <2 x i64> @test_extrqi_constant_poison(<2 x i64> %x) {
define <2 x i64> @test_extrqi_call_constexpr() {
; CHECK-LABEL: @test_extrqi_call_constexpr(
-; CHECK-NEXT: ret <2 x i64> zeroinitializer
+; CHECK-NEXT: ret <2 x i64> <i64 0, i64 undef>
;
%1 = tail call <2 x i64> @llvm.x86.sse4a.extrqi(<2 x i64> bitcast (<16 x i8> trunc (<16 x i16> bitcast (<4 x i64> <i64 0, i64 poison, i64 2, i64 poison> to <16 x i16>) to <16 x i8>) to <2 x i64>), i8 8, i8 16)
ret <2 x i64> %1
diff --git a/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll b/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
index 6277986288a8c..237deac09dece 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
@@ -138,7 +138,7 @@ define <2 x i64> @test_extrqi_constant_undef(<2 x i64> %x) {
define <2 x i64> @test_extrqi_call_constexpr() {
; CHECK-LABEL: @test_extrqi_call_constexpr(
-; CHECK-NEXT: ret <2 x i64> zeroinitializer
+; CHECK-NEXT: ret <2 x i64> <i64 0, i64 undef>
;
%1 = tail call <2 x i64> @llvm.x86.sse4a.extrqi(<2 x i64> bitcast (<16 x i8> trunc (<16 x i16> bitcast (<4 x i64> <i64 0, i64 undef, i64 2, i64 undef> to <16 x i16>) to <16 x i8>) to <2 x i64>), i8 8, i8 16)
ret <2 x i64> %1
diff --git a/llvm/test/Transforms/InstCombine/cast.ll b/llvm/test/Transforms/InstCombine/cast.ll
index 6047d61e8dbff..b82cb23acc29b 100644
--- a/llvm/test/Transforms/InstCombine/cast.ll
+++ b/llvm/test/Transforms/InstCombine/cast.ll
@@ -1438,10 +1438,10 @@ define i32 @test89() {
define <2 x i32> @test90() {
; BE-LABEL: @test90(
-; BE-NEXT: ret <2 x i32> <i32 0, i32 15360>
+; BE-NEXT: ret <2 x i32> <i32 poison, i32 15360>
;
; LE-LABEL: @test90(
-; LE-NEXT: ret <2 x i32> <i32 0, i32 1006632960>
+; LE-NEXT: ret <2 x i32> <i32 poison, i32 1006632960>
;
%t6 = bitcast <4 x half> <half poison, half poison, half poison, half 0xH3C00> to <2 x i32>
ret <2 x i32> %t6
diff --git a/llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll b/llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll
index d2656e291547c..be00d78fc88d5 100644
--- a/llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll
+++ b/llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll
@@ -1,59 +1,80 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
-; RUN: opt < %s -passes=instsimplify -use-constant-fp-for-fixed-length-splat -use-constant-int-for-fixed-length-splat -S | FileCheck %s
-target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-f64:32:64-v64:64:64-v128:128:128"
+; RUN: opt < %s -passes=instsimplify -S -data-layout="e-p:32:32:32-i1:8:8-i8:8:8-f64:32:64-v64:64:64-v128:128:128" | FileCheck %s --check-prefixes=CHECK,LE
+; RUN: opt < %s -passes=instsimplify -use-constant-fp-for-fixed-length-splat -use-constant-int-for-fixed-length-splat -S -data-layout="e-p:32:32:32-i1:8:8-i8:8:8-f64:32:64-v64:64:64-v128:128:128" | FileCheck %s --check-prefixes=CHECK,LE
+; RUN: opt < %s -passes=instsimplify -S -data-layout="E-p:32:32:32-i1:8:8-i8:8:8-f64:32:64-v64:64:64-v128:128:128" | FileCheck %s --check-prefixes=CHECK,BE
define <2 x i64> @test1() {
-; CHECK-LABEL: @test1(
-; CHECK-NEXT: ret <2 x i64> <i64 4294967296, i64 12884901890>
+; LE-LABEL: @test1(
+; LE-NEXT: ret <2 x i64> <i64 4294967296, i64 12884901890>
+;
+; BE-LABEL: @test1(
+; BE-NEXT: ret <2 x i64> <i64 1, i64 8589934595>
;
%tmp3 = bitcast <4 x i32> < i32 0, i32 1, i32 2, i32 3 > to <2 x i64>
ret <2 x i64> %tmp3
}
define <4 x i32> @test2() {
-; CHECK-LABEL: @test2(
-; CHECK-NEXT: ret <4 x i32> <i32 0, i32 0, i32 1, i32 0>
+; LE-LABEL: @test2(
+; LE-NEXT: ret <4 x i32> <i32 0, i32 0, i32 1, i32 0>
+;
+; BE-LABEL: @test2(
+; BE-NEXT: ret <4 x i32> <i32 0, i32 0, i32 0, i32 1>
;
%tmp3 = bitcast <2 x i64> < i64 0, i64 1 > to <4 x i32>
ret <4 x i32> %tmp3
}
define <2 x double> @test3() {
-; CHECK-LABEL: @test3(
-; CHECK-NEXT: ret <2 x double> <double 0x100000000, double 0x300000002>
+; LE-LABEL: @test3(
+; LE-NEXT: ret <2 x double> <double 0x100000000, double 0x300000002>
+;
+; BE-LABEL: @test3(
+; BE-NEXT: ret <2 x double> <double 4.940660e-324, double 0x200000003>
;
%tmp3 = bitcast <4 x i32> < i32 0, i32 1, i32 2, i32 3 > to <2 x double>
ret <2 x double> %tmp3
}
define <4 x float> @test4() {
-; CHECK-LABEL: @test4(
-; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0x36A0000000000000, float 0.000000e+00>
+; LE-LABEL: @test4(
+; LE-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0x36A0000000000000, float 0.000000e+00>
+;
+; BE-LABEL: @test4(
+; BE-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0x36A0000000000000>
;
%tmp3 = bitcast <2 x i64> < i64 0, i64 1 > to <4 x float>
ret <4 x float> %tmp3
}
define <2 x i64> @test5() {
-; CHECK-LABEL: @test5(
-; CHECK-NEXT: ret <2 x i64> <i64 4575657221408423936, i64 4629700418010611712>
+; LE-LABEL: @test5(
+; LE-NEXT: ret <2 x i64> <i64 4575657221408423936, i64 4629700418010611712>
+;
+; BE-LABEL: @test5(
+; BE-NEXT: ret <2 x i64> <i64 1065353216, i64 4611686019505324032>
;
%tmp3 = bitcast <4 x float> <float 0.0, float 1.0, float 2.0, float 3.0> to <2 x i64>
ret <2 x i64> %tmp3
}
define <4 x i32> @test6() {
-; CHECK-LABEL: @test6(
-; CHECK-NEXT: ret <4 x i32> <i32 0, i32 1071644672, i32 0, i32 1072693248>
+; LE-LABEL: @test6(
+; LE-NEXT: ret <4 x i32> <i32 0, i32 1071644672, i32 0, i32 1072693248>
+;
+; BE-LABEL: @test6(
+; BE-NEXT: ret <4 x i32> <i32 1071644672, i32 0, i32 1072693248, i32 0>
;
%tmp3 = bitcast <2 x double> <double 0.5, double 1.0> to <4 x i32>
ret <4 x i32> %tmp3
}
define i32 @test7() {
-; CHECK-LABEL: @test7(
-; CHECK-NEXT: ret i32 1118464
+; LE-LABEL: @test7(
+; LE-NEXT: ret i32 1118464
+;
+; BE-LABEL: @test7(
+; BE-NEXT: ret i32 285212689
;
%tmp3 = bitcast <2 x half> <half 0xH1100, half 0xH0011> to i32
ret i32 %tmp3
@@ -83,6 +104,50 @@ define <1 x i1> @test10() {
ret <1 x i1> %ret
}
+define <4 x i24> @test11() {
+; LE-LABEL: @test11(
+; LE-NEXT: ret <4 x i24> <i24 1, i24 256, i24 65536, i24 0>
+;
+; BE-LABEL: @test11(
+; BE-NEXT: ret <4 x i24> <i24 0, i24 65536, i24 256, i24 1>
+;
+ %c = bitcast <3 x i32> <i32 1, i32 1, i32 1> to <4 x i24>
+ ret <4 x i24> %c
+}
+
+define <8 x i24> @test12() {
+; LE-LABEL: @test12(
+; LE-NEXT: ret <8 x i24> splat (i24 1)
+;
+; BE-LABEL: @test12(
+; BE-NEXT: ret <8 x i24> <i24 256, i24 256, i24 257, i24 1, i24 1, i24 0, i24 65536, i24 65536>
+;
+ %c = bitcast <3 x i64> <i64 281474993487873, i64 72057598332895488, i64 1099511693312> to <8 x i24>
+ ret <8 x i24> %c
+}
+
+define <3 x i32> @test13() {
+; LE-LABEL: @test13(
+; LE-NEXT: ret <3 x i32> splat (i32 1)
+;
+; BE-LABEL: @test13(
+; BE-NEXT: ret <3 x i32> <i32 256, i32 16777472, i32 0>
+;
+ %c = bitcast <4 x i24> <i24 1, i24 256, i24 65536, i24 0> to <3 x i32>
+ ret <3 x i32> %c
+}
+
+define <3 x i64> @test14() {
+; LE-LABEL: @test14(
+; LE-NEXT: ret <3 x i64> <i64 281474993487873, i64 72057598332895488, i64 1099511693312>
+;
+; BE-LABEL: @test14(
+; BE-NEXT: ret <3 x i64> <i64 1099511693312, i64 72057598332895488, i64 281474993487873>
+;
+ %c = bitcast <8 x i24> splat (i24 1) to <3 x i64>
+ ret <3 x i64> %c
+}
+
; from MultiSource/Benchmarks/Bullet
define <2 x float> @foo() {
; CHECK-LABEL: @foo(
@@ -134,149 +199,225 @@ define <2 x double> @foo6() {
}
define <4 x i32> @bitcast_constexpr_4i32_2i64_u2() {
-; CHECK-LABEL: @bitcast_constexpr_4i32_2i64_u2(
-; CHECK-NEXT: ret <4 x i32> <i32 undef, i32 undef, i32 2, i32 0>
+; LE-LABEL: @bitcast_constexpr_4i32_2i64_u2(
+; LE-NEXT: ret <4 x i32> <i32 undef, i32 undef, i32 2, i32 0>
+;
+; BE-LABEL: @bitcast_constexpr_4i32_2i64_u2(
+; BE-NEXT: ret <4 x i32> <i32 undef, i32 undef, i32 0, i32 2>
;
%cast = bitcast <2 x i64><i64 undef, i64 2> to <4 x i32>
ret <4 x i32> %cast
}
define <4 x i32> @bitcast_constexpr_4i32_2i64_1u() {
-; CHECK-LABEL: @bitcast_constexpr_4i32_2i64_1u(
-; CHECK-NEXT: ret <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
+; LE-LABEL: @bitcast_constexpr_4i32_2i64_1u(
+; LE-NEXT: ret <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
+;
+; BE-LABEL: @bitcast_constexpr_4i32_2i64_1u(
+; BE-NEXT: ret <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
;
%cast = bitcast <2 x i64><i64 1, i64 undef> to <4 x i32>
ret <4 x i32> %cast
}
define <4 x i32> @bitcast_constexpr_4i32_2i64() {
-; CHECK-LABEL: @bitcast_constexpr_4i32_2i64(
-; CHECK-NEXT: ret <4 x i32> <i32 undef, i32 undef, i32 2, i32 0>
+; LE-LABEL: @bitcast_constexpr_4i32_2i64(
+; LE-NEXT: ret <4 x i32> <i32 undef, i32 undef, i32 2, i32 0>
+;
+; BE-LABEL: @bitcast_constexpr_4i32_2i64(
+; BE-NEXT: ret <4 x i32> <i32 undef, i32 undef, i32 0, i32 2>
;
%cast = bitcast <2 x i64><i64 undef, i64 2> to <4 x i32>
ret <4 x i32> %cast
}
define <8 x i16> @bitcast_constexpr_8i16_2i64_u2() {
-; CHECK-LABEL: @bitcast_constexpr_8i16_2i64_u2(
-; CHECK-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 2, i16 0, i16 0, i16 0>
+; LE-LABEL: @bitcast_constexpr_8i16_2i64_u2(
+; LE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 2, i16 0, i16 0, i16 0>
+;
+; BE-LABEL: @bitcast_constexpr_8i16_2i64_u2(
+; BE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 0, i16 0, i16 0, i16 2>
;
%cast = bitcast <2 x i64><i64 undef, i64 2> to <8 x i16>
ret <8 x i16> %cast
}
define <8 x i16> @bitcast_constexpr_8i16_2i64_1u() {
-; CHECK-LABEL: @bitcast_constexpr_8i16_2i64_1u(
-; CHECK-NEXT: ret <8 x i16> <i16 1, i16 0, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
+; LE-LABEL: @bitcast_constexpr_8i16_2i64_1u(
+; LE-NEXT: ret <8 x i16> <i16 1, i16 0, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
+;
+; BE-LABEL: @bitcast_constexpr_8i16_2i64_1u(
+; BE-NEXT: ret <8 x i16> <i16 0, i16 0, i16 0, i16 1, i16 undef, i16 undef, i16 undef, i16 undef>
;
%cast = bitcast <2 x i64><i64 1, i64 undef> to <8 x i16>
ret <8 x i16> %cast
}
define <8 x i16> @bitcast_constexpr_8i16_2i64_u65536() {
-; CHECK-LABEL: @bitcast_constexpr_8i16_2i64_u65536(
-; CHECK-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 0, i16 1, i16 0, i16 0>
+; LE-LABEL: @bitcast_constexpr_8i16_2i64_u65536(
+; LE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 0, i16 1, i16 0, i16 0>
+;
+; BE-LABEL: @bitcast_constexpr_8i16_2i64_u65536(
+; BE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 0, i16 0, i16 1, i16 0>
;
%cast = bitcast <2 x i64><i64 undef, i64 65536> to <8 x i16>
ret <8 x i16> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_2i64_u2() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_2i64_u2(
-; CHECK-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>
+; LE-LABEL: @bitcast_constexpr_16i8_2i64_u2(
+; LE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_2i64_u2(
+; BE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 2>
;
%cast = bitcast <2 x i64><i64 undef, i64 2> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_2i64_256u() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_2i64_256u(
-; CHECK-NEXT: ret <16 x i8> <i8 0, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
+; LE-LABEL: @bitcast_constexpr_16i8_2i64_256u(
+; LE-NEXT: ret <16 x i8> <i8 0, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_2i64_256u(
+; BE-NEXT: ret <16 x i8> <i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 1, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
;
%cast = bitcast <2 x i64><i64 256, i64 undef> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_2i64_u256() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_2i64_u256(
-; CHECK-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>
+; LE-LABEL: @bitcast_constexpr_16i8_2i64_u256(
+; LE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_2i64_u256(
+; BE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 1, i8 0>
;
%cast = bitcast <2 x i64><i64 undef, i64 256> to <16 x i8>
ret <16 x i8> %cast
}
define <8 x i16> @bitcast_constexpr_8i16_4i32_uu22() {
-; CHECK-LABEL: @bitcast_constexpr_8i16_4i32_uu22(
-; CHECK-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 2, i16 0, i16 2, i16 0>
+; LE-LABEL: @bitcast_constexpr_8i16_4i32_uu22(
+; LE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 2, i16 0, i16 2, i16 0>
+;
+; BE-LABEL: @bitcast_constexpr_8i16_4i32_uu22(
+; BE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 undef, i16 undef, i16 0, i16 2, i16 0, i16 2>
;
%cast = bitcast <4 x i32><i32 undef, i32 undef, i32 2, i32 2> to <8 x i16>
ret <8 x i16> %cast
}
define <8 x i16> @bitcast_constexpr_8i16_4i32_10uu() {
-; CHECK-LABEL: @bitcast_constexpr_8i16_4i32_10uu(
-; CHECK-NEXT: ret <8 x i16> <i16 1, i16 0, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
+; LE-LABEL: @bitcast_constexpr_8i16_4i32_10uu(
+; LE-NEXT: ret <8 x i16> <i16 1, i16 0, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
+;
+; BE-LABEL: @bitcast_constexpr_8i16_4i32_10uu(
+; BE-NEXT: ret <8 x i16> <i16 0, i16 1, i16 0, i16 0, i16 undef, i16 undef, i16 undef, i16 undef>
;
%cast = bitcast <4 x i32><i32 1, i32 0, i32 undef, i32 undef> to <8 x i16>
ret <8 x i16> %cast
}
define <8 x i16> @bitcast_constexpr_8i16_4i32_u257u256() {
-; CHECK-LABEL: @bitcast_constexpr_8i16_4i32_u257u256(
-; CHECK-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 0, i16 1, i16 undef, i16 undef, i16 0, i16 1>
+; LE-LABEL: @bitcast_constexpr_8i16_4i32_u257u256(
+; LE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 0, i16 1, i16 undef, i16 undef, i16 0, i16 1>
+;
+; BE-LABEL: @bitcast_constexpr_8i16_4i32_u257u256(
+; BE-NEXT: ret <8 x i16> <i16 undef, i16 undef, i16 1, i16 0, i16 undef, i16 undef, i16 1, i16 0>
;
%cast = bitcast <4 x i32><i32 undef, i32 65536, i32 undef, i32 65536> to <8 x i16>
ret <8 x i16> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_4i32_u2u2() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_4i32_u2u2(
-; CHECK-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0>
+; LE-LABEL: @bitcast_constexpr_16i8_4i32_u2u2(
+; LE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 2, i8 0, i8 0, i8 0>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_4i32_u2u2(
+; BE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 0, i8 0, i8 2, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 0, i8 0, i8 2>
;
%cast = bitcast <4 x i32><i32 undef, i32 2, i32 undef, i32 2> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_4i32_1u1u() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_4i32_1u1u(
-; CHECK-NEXT: ret <16 x i8> <i8 1, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 1, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef>
+; LE-LABEL: @bitcast_constexpr_16i8_4i32_1u1u(
+; LE-NEXT: ret <16 x i8> <i8 1, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 1, i8 0, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_4i32_1u1u(
+; BE-NEXT: ret <16 x i8> <i8 0, i8 0, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 0, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef>
;
%cast = bitcast <4 x i32><i32 1, i32 undef, i32 1, i32 undef> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_4i32_u256uu() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_4i32_u256uu(
-; CHECK-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
+; LE-LABEL: @bitcast_constexpr_16i8_4i32_u256uu(
+; LE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 0, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_4i32_u256uu(
+; BE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 0, i8 1, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef>
;
%cast = bitcast <4 x i32><i32 undef, i32 256, i32 undef, i32 undef> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_8i16_u2u2u2u2() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_8i16_u2u2u2u2(
-; CHECK-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0>
+; LE-LABEL: @bitcast_constexpr_16i8_8i16_u2u2u2u2(
+; LE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0, i8 undef, i8 undef, i8 2, i8 0>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_8i16_u2u2u2u2(
+; BE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 0, i8 2, i8 undef, i8 undef, i8 0, i8 2, i8 undef, i8 undef, i8 0, i8 2, i8 undef, i8 undef, i8 0, i8 2>
;
%cast = bitcast <8 x i16><i16 undef, i16 2, i16 undef, i16 2, i16 undef, i16 2, i16 undef, i16 2> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_8i16_1u1u1u1u() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_8i16_1u1u1u1u(
-; CHECK-NEXT: ret <16 x i8> <i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef>
+; LE-LABEL: @bitcast_constexpr_16i8_8i16_1u1u1u1u(
+; LE-NEXT: ret <16 x i8> <i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_8i16_1u1u1u1u(
+; BE-NEXT: ret <16 x i8> <i8 0, i8 1, i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef>
;
%cast = bitcast <8 x i16><i16 1, i16 undef, i16 1, i16 undef, i16 1, i16 undef, i16 1, i16 undef> to <16 x i8>
ret <16 x i8> %cast
}
define <16 x i8> @bitcast_constexpr_16i8_8i16_u256uuu256uu() {
-; CHECK-LABEL: @bitcast_constexpr_16i8_8i16_u256uuu256uu(
-; CHECK-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef>
+; LE-LABEL: @bitcast_constexpr_16i8_8i16_u256uuu256uu(
+; LE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 0, i8 1, i8 undef, i8 undef, i8 undef, i8 undef>
+;
+; BE-LABEL: @bitcast_constexpr_16i8_8i16_u256uuu256uu(
+; BE-NEXT: ret <16 x i8> <i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 undef, i8 1, i8 0, i8 undef, i8 undef, i8 undef, i8 undef>
;
%cast = bitcast <8 x i16><i16 undef, i16 256, i16 undef, i16 undef, i16 undef, i16 256, i16 undef, i16 undef> to <16 x i8>
ret <16 x i8> %cast
}
+define <4 x i24> @bitcast_constexpr_4i24_3i32_u1u() {
+; LE-LABEL: @bitcast_constexpr_4i24_3i32_u1u(
+; LE-NEXT: ret <4 x i24> <i24 undef, i24 256, i24 0, i24 undef>
+;
+; BE-LABEL: @bitcast_constexpr_4i24_3i32_u1u(
+; BE-NEXT: ret <4 x i24> <i24 undef, i24 0, i24 256, i24 undef>
+;
+ %cast = bitcast <3 x i32><i32 undef, i32 1, i32 undef> to <4 x i24>
+ ret <4 x i24> %cast
+}
+
+define <3 x i32> @bitcast_constexpr_3i32_4i24_n1255uu() {
+; LE-LABEL: @bitcast_constexpr_3i32_4i24_n1255uu(
+; LE-NEXT: ret <3 x i32> <i32 -1, i32 0, i32 undef>
+;
+; BE-LABEL: @bitcast_constexpr_3i32_4i24_n1255uu(
+; BE-NEXT: ret <3 x i32> <i32 -256, i32 0, i32 undef>
+;
+ %cast = bitcast <4 x i24><i24 -1, i24 255, i24 undef, i24 undef> to <3 x i32>
+ ret <3 x i32> %cast
+}
+
define <1 x i32> @bitcast_constexpr_scalar_fp_to_vector_int() {
; CHECK-LABEL: @bitcast_constexpr_scalar_fp_to_vector_int(
; CHECK-NEXT: ret <1 x i32> splat (i32 1065353216)
diff --git a/llvm/test/Transforms/SCCP/bitcast-vector-refinement.l.ll b/llvm/test/Transforms/SCCP/bitcast-vector-refinement.l.ll
index 94df835e317b7..754f749128869 100644
--- a/llvm/test/Transforms/SCCP/bitcast-vector-refinement.l.ll
+++ b/llvm/test/Transforms/SCCP/bitcast-vector-refinement.l.ll
@@ -10,8 +10,7 @@ define <32 x i8> @test(i1 %cond) {
; CHECK-NEXT: [[TMP0:%.*]] = phi <4 x i64> [ zeroinitializer, %[[ENTRY]] ], [ splat (i64 1), %[[FOR_COND2]] ]
; CHECK-NEXT: br i1 [[COND]], label %[[FOR_COND2]], label %[[IF_THEN:.*]]
; CHECK: [[IF_THEN]]:
-; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i64> zeroinitializer to <32 x i8>
-; CHECK-NEXT: ret <32 x i8> [[TMP1]]
+; CHECK-NEXT: ret <32 x i8> zeroinitializer
;
entry:
br label %for.cond2
More information about the llvm-commits
mailing list