[all-commits] [llvm/llvm-project] 4ff7ac: [SeparateConstOffsetFromGEP] Add test case with tr...

Björn Pettersson via All-commits all-commits at lists.llvm.org
Fri Aug 22 01:29:58 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4ff7ac23301bee8cab04993b6047e360571adde3
      https://github.com/llvm/llvm-project/commit/4ff7ac23301bee8cab04993b6047e360571adde3
  Author: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2025-08-22 (Fri, 22 Aug 2025)

  Changed paths:
    A llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/rebuild-trunc.ll

  Log Message:
  -----------
  [SeparateConstOffsetFromGEP] Add test case with trunc nuw/nsw showing miscompile

Pre commit a test case for issue #154116. When redistributing
trunc over add/sub/or we may need to drop poison generating flags
from the trunc.


  Commit: 2d3167f8d86ca9bdaff44cf839488c5a513f5583
      https://github.com/llvm/llvm-project/commit/2d3167f8d86ca9bdaff44cf839488c5a513f5583
  Author: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2025-08-22 (Fri, 22 Aug 2025)

  Changed paths:
    M llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
    M llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/preserve-inbounds.ll
    M llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/rebuild-trunc.ll

  Log Message:
  -----------
  [SeparateConstOffsetFromGEP] Avoid miscompiles related to trunc nuw/nsw (#154582)

Drop poison generating flags on trunc when distributing trunc over
add/sub/or. We need to do this since for example
(add (trunc nuw A), (trunc nuw B)) is more poisonous than
(trunc nuw (add A, B))).

In some situations it is pessimistic to drop the flags. Such as
if the add in the example above also has the nuw flag. For now we
keep it simple and always drop the flags.

Worth mentioning is that we drop the flags when cloning
instructions and rebuilding the chain. This is done after the
"allowsPreservingNUW" checks in ConstantOffsetExtractor::Extract.
So we still take the "trunc nuw" into consideration when determining
if nuw can be preserved in the gep (which should be ok since that
check also require that all the involved binary operations has nuw).

Fixes #154116


Compare: https://github.com/llvm/llvm-project/compare/8d7df8bba134...2d3167f8d86c

To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list