[all-commits] [llvm/llvm-project] c1fd54: [InstCombine] Fold zext(sub(0, trunc(X))) to and(s...

Ayaan via All-commits all-commits at lists.llvm.org
Wed Jul 8 03:52:10 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c1fd542e61749f3c6765f4d8293094e7064ebb18
      https://github.com/llvm/llvm-project/commit/c1fd542e61749f3c6765f4d8293094e7064ebb18
  Author: Ayaan <138162656+def3r at users.noreply.github.com>
  Date:   2026-07-08 (Wed, 08 Jul 2026)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
    M llvm/test/Transforms/InstCombine/rotate.ll
    A llvm/test/Transforms/InstCombine/zext-sub-trunc.ll

  Log Message:
  -----------
  [InstCombine] Fold zext(sub(0, trunc(X))) to and(sub(0, X), mask) (#207564)

Problem: vector rotate and funnel shift fails to fold for vectors > 16
bytes on AVX-512. This is because of the `trunc` and `zext`
instructions.

Example:
```llvm
define dso_local <8 x i64> @baz(<8 x i64> %0, <8 x i64> %1) local_unnamed_addr {
Entry:
  %2 = trunc <8 x i64> %1 to <8 x i6>
  %3 = sub <8 x i6> zeroinitializer, %2
  %4 = zext <8 x i6> %3 to <8 x i64>
  %5 = shl <8 x i64> %0, %4
  %6 = and <8 x i64> %1, splat (i64 63)
  %7 = lshr <8 x i64> %0, %6
  %8 = or <8 x i64> %5, %7
  ret <8 x i64> %8
}
```   

Solution; Canonicalize the transformation `zext(sub(0, trunc(X))) ->
and(sub(0, X), mask)` for scalars and vectors.

Closes #165306



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