Skip to content

Instantly share code, notes, and snippets.

@nikic
Created June 29, 2022 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/a4daeb24294f1f16ed45a531bcfaa146 to your computer and use it in GitHub Desktop.
Save nikic/a4daeb24294f1f16ed45a531bcfaa146 to your computer and use it in GitHub Desktop.
commit 2ef6645d1a7297f426324d954be064d445924590
Author: Nikita Popov <npopov@redhat.com>
Date: Wed Jun 29 14:16:30 2022 +0200
restore bitcast upgrade
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h b/llvm/include/llvm/IR/AutoUpgrade.h
index 96d20a7aefb1..12952f25cbda 100644
--- a/llvm/include/llvm/IR/AutoUpgrade.h
+++ b/llvm/include/llvm/IR/AutoUpgrade.h
@@ -82,7 +82,7 @@ namespace llvm {
/// This is an auto-upgrade for bitcast constant expression between pointers
/// with different address spaces: the instruction is replaced by a pair
/// ptrtoint+inttoptr.
- Value *UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy);
+ Constant *UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy);
/// Check the debug info version number, if it is out-dated, drop the debug
/// info. Return true if module is modified.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 7abe7c0d93dd..5e5ca96aeb55 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1442,7 +1442,9 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
if (isConstExprSupported(BC->Opcode) && ConstOps.size() == Ops.size()) {
Constant *C;
if (Instruction::isCast(BC->Opcode)) {
- C = ConstantExpr::getCast(BC->Opcode, ConstOps[0], BC->getType());
+ C = UpgradeBitCastExpr(BC->Opcode, ConstOps[0], BC->getType());
+ if (!C)
+ C = ConstantExpr::getCast(BC->Opcode, ConstOps[0], BC->getType());
} else if (Instruction::isUnaryOp(BC->Opcode)) {
C = ConstantExpr::get(BC->Opcode, ConstOps[0], BC->Flags);
} else if (Instruction::isBinaryOp(BC->Opcode)) {
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 2a4c31534fa4..75594f90c926 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4179,7 +4179,7 @@ Instruction *llvm::UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy,
return nullptr;
}
-Value *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) {
+Constant *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) {
if (Opc != Instruction::BitCast)
return nullptr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment