Skip to content

Commit 2f5cc5b

Browse files
Prevent bogus return when constant fold does not happen.
Rather then return the correct result I believe we do not hit this issue because the input has been restricted to constants that we know can be constant folded and so I've replace the broken code with an assert, which is in keeping with the other code in this area that requires constant folding to work.
1 parent e0858b1 commit 2f5cc5b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
200200
IntegerType::get(C->getContext(), FPWidth), NumSrcElt);
201201
// Ask IR to do the conversion now that #elts line up.
202202
C = ConstantExpr::getBitCast(C, SrcIVTy);
203-
// If IR wasn't able to fold it, bail out.
204-
if (!isa<ConstantVector>(C) && // FIXME: Remove ConstantVector.
205-
!isa<ConstantDataVector>(C))
206-
return C;
203+
assert((isa<ConstantVector>(C) || // FIXME: Remove ConstantVector.
204+
isa<ConstantDataVector>(C) || isa<ConstantInt>(C) ||
205+
isa<ConstantFP>(C)) &&
206+
"Constant folding cannot fail for plain fp->int bitcast!");
207207
}
208208

209209
// Now we know that the input and output vectors are both integer vectors

llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,11 @@ define <1 x i32> @bitcast_constexpr_scalar_fp_to_vector_int() {
284284
%res = bitcast float 1.0 to <1 x i32>
285285
ret <1 x i32> %res
286286
}
287+
288+
define <2 x i64> @bitcast_constexpr_4f32_2i64_1111() {
289+
; CHECK-LABEL: @bitcast_constexpr_4f32_2i64_1111(
290+
; CHECK-NEXT: ret <2 x i64> splat (i64 4575657222473777152)
291+
;
292+
%res = bitcast <4 x float> splat (float 1.0) to <2 x i64>
293+
ret <2 x i64> %res
294+
}

0 commit comments

Comments
 (0)