[llvm] EarlyCSE: create casts on type-mismatch (PR #113339)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 16:30:02 PDT 2024


================
@@ -964,32 +965,45 @@ class EarlyCSE {
   bool overridingStores(const ParseMemoryInst &Earlier,
                         const ParseMemoryInst &Later);
 
-  Value *getOrCreateResult(Value *Inst, Type *ExpectedType) const {
-    // TODO: We could insert relevant casts on type mismatch here.
-    if (auto *LI = dyn_cast<LoadInst>(Inst))
-      return LI->getType() == ExpectedType ? LI : nullptr;
-    if (auto *SI = dyn_cast<StoreInst>(Inst)) {
-      Value *V = SI->getValueOperand();
-      return V->getType() == ExpectedType ? V : nullptr;
+  Value *getOrCreateResult(Instruction *Inst, Type *ExpectedType) const {
+    if (!isa<IntrinsicInst, LoadInst, StoreInst>(Inst))
+      llvm_unreachable("Instruction not supported");
+
+    // The load or the store's first operand.
+    Value *V;
+    if (auto *II = dyn_cast<IntrinsicInst>(Inst)) {
+      if (isHandledNonTargetIntrinsic(II->getIntrinsicID()))
----------------
arsenm wrote:

isHandledNonTargetIntrinsic is redundant with just switching over the handled IDs 

https://github.com/llvm/llvm-project/pull/113339


More information about the llvm-commits mailing list