[llvm] Adjust bit cast instruction filter for DXIL Prepare pass (PR #142678)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 17:24:33 PDT 2025


================
@@ -148,9 +148,50 @@ class DXILPrepareModule : public ModulePass {
                                      Type *Ty) {
     // Omit bitcasts if the incoming value matches the instruction type.
     auto It = PointerTypes.find(Operand);
-    if (It != PointerTypes.end())
-      if (cast<TypedPointerType>(It->second)->getElementType() == Ty)
+    if (It != PointerTypes.end()) {
+      auto *OpTy = cast<TypedPointerType>(It->second)->getElementType();
+      if (OpTy == Ty)
         return nullptr;
+    }
+
+    // Also omit the bitcast for matching global array types
+    if (auto *GlobalVar = dyn_cast<GlobalVariable>(Operand)) {
+      Type *ValTy = GlobalVar->getValueType();
+
+      if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
+        Type *ElTy = ArrTy->getElementType();
+        if (ElTy == Ty)
+          return nullptr;
+      }
+    }
+
+    // Also omit the bitcast for alloca instructions
+    if (auto *AI = dyn_cast<AllocaInst>(Operand)) {
----------------
farzonl wrote:

this is pseudo code so adjust it to something that works.

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


More information about the llvm-commits mailing list