[all-commits] [llvm/llvm-project] 3aed08: [AggressiveInstCombine] Fold split-width i32 cttz/...

Usha Gupta via All-commits all-commits at lists.llvm.org
Mon Apr 27 02:30:54 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3aed0816fed922391ed0638f67ea8b6d09bebbdc
      https://github.com/llvm/llvm-project/commit/3aed0816fed922391ed0638f67ea8b6d09bebbdc
  Author: Usha Gupta <usha.gupta at arm.com>
  Date:   2026-04-27 (Mon, 27 Apr 2026)

  Changed paths:
    M llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
    A llvm/test/Transforms/AggressiveInstCombine/fold-split-ctlz.ll
    A llvm/test/Transforms/AggressiveInstCombine/fold-split-cttz.ll

  Log Message:
  -----------
  [AggressiveInstCombine] Fold split-width i32 cttz/ctlz patterns into wide i64 intrinsics (#192296)

This patch teaches `AggressiveInstCombine ` to recognize and fold common split-width i32 cttz/ctlz intrinsic calls into a single full-width i64
cttz/ctlz intrinsic.

For ex:
```
define i32 @src(i64 %val) {
 %lo = trunc i64 %val to i32
 %cmp = icmp eq i32 %lo, 0
 %shr = lshr i64 %val, 32
 %hi = trunc i64 %shr to i32
 %cttz_hi = call i32 @llvm.cttz.i32(i32 %hi, i1 true)
 %hi_plus32 = or i32 %cttz_hi, 32
 %cttz_lo = call i32 @llvm.cttz.i32(i32 %lo, i1 true)
 %result = select i1 %cmp, i32 %hi_plus32, i32 %cttz_lo
 ret i32 %result
}

define i32 @tgt(i64 %val)  {
%cttz64 = call i64 @llvm.cttz.i64(i64 %val, i1 false)
%result = trunc i64 %cttz64 to i32
ret i32 %result
}
```
and similarly for ctlz intrinsic.

Alive proof for the 2 folds added by this patch.
cttz:
https://alive2.llvm.org/ce/z/-s14-s

ctlz:
https://alive2.llvm.org/ce/z/WfQepH



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