[llvm] [InstCombine] Evaluate zext nneg as sext where possible (PR #212230)

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 04:34:35 PDT 2026


================
@@ -1602,11 +1606,21 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
   if (SrcTy->isIntOrIntVectorTy(1) && Zext.hasNonNeg())
     return replaceInstUsesWith(Zext, Constant::getNullValue(Zext.getType()));
 
+  // zext nneg means Src is non-negative and we can treat this as an sext, and
+  // if no signed wrapping occurs we know that Src evaluated as a signed
+  // DestTy will also be non-negative. Evaluating as a signed type means that
+  // any constant operands will be sign-extended instead of zero-extended,
+  // meaning they remain in the range of a signed SrcTy so we won't need to
+  // clear any high bits.
+  bool EvaluateAsSigned =
----------------
john-brawn-arm wrote:

That feels a little beyond the scope of this PR. I've added a test with a FIXME comment.

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


More information about the llvm-commits mailing list