Skip to content

Commit d6d44d6

Browse files
committed
[ConstantFolding] Avoid use of ConstantExpr::getZExt() (NFC)
Use the constant folding API instead, which should always succeed in this case.
1 parent be30cd6 commit d6d44d6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,16 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
227227
return ConstantExpr::getBitCast(C, DestTy);
228228

229229
// Zero extend the element to the right size.
230-
Src = ConstantExpr::getZExt(Src, Elt->getType());
230+
Src = ConstantFoldCastOperand(Instruction::ZExt, Src, Elt->getType(),
231+
DL);
232+
assert(Src && "Constant folding cannot fail on plain integers");
231233

232234
// Shift it to the right place, depending on endianness.
233-
Src = ConstantExpr::getShl(Src,
234-
ConstantInt::get(Src->getType(), ShiftAmt));
235+
Src = ConstantFoldBinaryOpOperands(
236+
Instruction::Shl, Src, ConstantInt::get(Src->getType(), ShiftAmt),
237+
DL);
238+
assert(Src && "Constant folding cannot fail on plain integers");
239+
235240
ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
236241

237242
// Mix it in.

0 commit comments

Comments
 (0)