[llvm] [InstCombine] Extend fcmp+select folding to minnum/maxnum intrinsics (PR #112088)

Alexey Bader via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 14 09:58:55 PDT 2024


================
@@ -3834,11 +3834,13 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
     // minnum/maxnum intrinsics.
     if (SIFPOp->hasNoNaNs() && SIFPOp->hasNoSignedZeros()) {
       Value *X, *Y;
----------------
bader wrote:

> But it extended the lifetimes of the 2 inputs

Sorry, I don't understand why the lifetime of inputs is extended. I think it should not change.

Before InstCombine
```
  %cmp = fcmp olt float %a, %b
  store i1 %cmp, ptr %p, align 1
  %select = select nnan nsz i1 %cmp, float float %a, float %b
```

After InstCombine
```
  %cmp = fcmp olt float %a, %b
  store i1 %cmp, ptr %p, align 1
  %select = call nnan nsz float @llvm.minnum.f32(float %a, float %b)
```

both `select` and `llvm.minnum` use `%a` and `%b` inputs but select also uses `%cmp`. From this code, it's not clear why intrinsic extends the lifetime of inputs. It even reduces the lifetime of `%cmp` variable. What am I missing?

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


More information about the llvm-commits mailing list