[llvm] [IR] Add nowrap flags for trunc instruction (PR #85592)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 30 06:23:41 PDT 2024


antoniofrighetto wrote:

@elhewaty Looks like we have to check that `dyn_cast` is actually applicable, as we may be dealing with `ConstantExpr`, not just `Instruction` (which is the case in the above function that leads to the crash), e.g.:
```diff
--- a/llvm/lib/IR/Operator.cpp
+++ b/llvm/lib/IR/Operator.cpp
@@ -28,8 +28,9 @@ bool Operator::hasPoisonGeneratingFlags() const {
     return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();
   }
   case Instruction::Trunc: {
-    auto *TI = dyn_cast<TruncInst>(this);
-    return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
+    if (auto *TI = dyn_cast<TruncInst>(this))
+      return TI->hasNoUnsignedWrap() || TI->hasNoSignedWrap();
+    return false;
   }
   case Instruction::UDiv:
   case Instruction::SDiv:
```

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


More information about the llvm-commits mailing list