[llvm] [InstCombine] Fold sext of an nsw binop on trunc nsw into a wide nsw … (PR #228530)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 17:04:20 PDT 2026


================
@@ -0,0 +1,253 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; sext(binop nsw (trunc nsw X), Y) is the same operation on X when X already
+; has the destination type. Y may be a constant or any other value of the
+; narrow type. Rebuilding that expression without nsw becomes a shl/ashr pair,
+; which SCEV cannot treat as a non-wrapping recurrence.
+; https://alive2.llvm.org/ce/z/CUWfpR
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
----------------
junfengd-nv wrote:

Without a datalayout, shouldChangeType(i32, i64) returns false, so the fold is not applied. 

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


More information about the llvm-commits mailing list