[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:23:40 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:
no what I mean was you see how you are casting `ValTy` to `ArrTy`? So before that do
```cpp
if (auto *AI = dyn_cast<AllocaInst>(Operand))
ValTy = AI->getAllocatedType();
ie
```cpp
Type *ValTy = Operand->getType();
if (auto *GlobalVar = dyn_cast<GlobalVariable>(Operand))
Type *ValTy = GlobalVar->getValueType();
if (auto *AI = dyn_cast<AllocaInst>(Operand))
ValTy = AI->getAllocatedType();
if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
Type *ElTy = ArrTy->getElementType();
if (ElTy == Ty)
return nullptr;
}
```
https://github.com/llvm/llvm-project/pull/142678
More information about the llvm-commits
mailing list