[ConstExpr] Don't create insertvalue expressions
authorNikita Popov <npopov@redhat.com>
Wed, 29 Jun 2022 08:48:40 +0000 (10:48 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 1 Jul 2022 07:23:28 +0000 (09:23 +0200)
In preparation for the removal in D128719, this stops creating
insertvalue constant expressions (well, unless they are directly
used in LLVM IR).

Differential Revision: https://reviews.llvm.org/D128792

clang/lib/CodeGen/ItaniumCXXABI.cpp
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/lib/Analysis/ConstantFolding.cpp

index c41b419..f0003c4 100644 (file)
@@ -962,7 +962,9 @@ ItaniumCXXABI::EmitMemberPointerConversion(const CastExpr *E,
   else
     dstAdj = llvm::ConstantExpr::getNSWAdd(srcAdj, adj);
 
-  return llvm::ConstantExpr::getInsertValue(src, dstAdj, 1);
+  llvm::Constant *res = ConstantFoldInsertValueInstruction(src, dstAdj, 1);
+  assert(res != nullptr && "Folding must succeed");
+  return res;
 }
 
 llvm::Constant *
index a360be5..93ac33c 100644 (file)
@@ -133,7 +133,7 @@ public:
     auto *CAgg = dyn_cast<Constant>(Agg);
     auto *CVal = dyn_cast<Constant>(Val);
     if (CAgg && CVal)
-      return Fold(ConstantExpr::getInsertValue(CAgg, CVal, IdxList));
+      return ConstantFoldInsertValueInstruction(CAgg, CVal, IdxList);
     return nullptr;
   }
 
index 9cf68dc..1243043 100644 (file)
@@ -123,7 +123,7 @@ public:
     auto *CAgg = dyn_cast<Constant>(Agg);
     auto *CVal = dyn_cast<Constant>(Val);
     if (CAgg && CVal)
-      return ConstantExpr::getInsertValue(CAgg, CVal, IdxList);
+      return ConstantFoldInsertValueInstruction(CAgg, CVal, IdxList);
     return nullptr;
   }
 
index 01092b4..b2b071c 100644 (file)
@@ -1093,7 +1093,7 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, unsigned Opcode,
   case Instruction::InsertElement:
     return ConstantExpr::getInsertElement(Ops[0], Ops[1], Ops[2]);
   case Instruction::InsertValue:
-    return ConstantExpr::getInsertValue(
+    return ConstantFoldInsertValueInstruction(
         Ops[0], Ops[1], cast<InsertValueInst>(InstOrCE)->getIndices());
   case Instruction::ShuffleVector:
     return ConstantExpr::getShuffleVector(