[llvm] [SeparateConstOffsetFromGEP] Stop distributing sext/zext over lossy trunc (PR #221381)
Fabian Ritter via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 02:51:33 PDT 2026
================
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -mtriple=x86_64-unknown-linux-gnu -passes=separate-const-offset-from-gep < %s | FileCheck %s
+
+; The nuw/nsw flags on an add hold at the width of the add, which says nothing
+; about wrapping at the width of a truncation applied to its result. A
+; sext/zext above such a truncation must therefore not be distributed into the
+; operands of the add.
+
+; zext i64 (trunc i8 (add nuw i32 A, B)) wraps modulo 256, so the constant 1
+; must stay inside the truncation. For A = 251 and B = 5 the index is 0, while
+; distributing the casts would give 251 + 5 = 256.
+define ptr addrspace(1) @zext_of_lossy_trunc(ptr addrspace(1) %p, i8 %a, i64 %iv) {
----------------
ritter-x2a wrote:
Is there a reason to not use the default addrspace (especially if the test is for x86)?
https://github.com/llvm/llvm-project/pull/221381
More information about the llvm-commits
mailing list