[llvm] [InstCombine] Fold `sext(trunc nsw)` and `zext(trunc nuw)` (PR #88609)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 26 12:12:08 PDT 2024


================
@@ -1188,9 +1188,19 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
   if (auto *CSrc = dyn_cast<TruncInst>(Src)) {   // A->B->C cast
     // TODO: Subsume this into EvaluateInDifferentType.
 
+    Value *A = CSrc->getOperand(0);
+    // If trunc has nuw flag, then convert directly to final type.
+    if (CSrc->hasNoUnsignedWrap()) {
----------------
goldsteinn wrote:

You can also handle `nsw` if the `zext` has `nneg`.

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


More information about the llvm-commits mailing list