[llvm] [InstCombine] Fix for folding `select` into floating point binary operators. (PR #83200)

Paul Osmialowski via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 22 07:25:31 PDT 2024


pawosm-arm wrote:

> It would be easier to reason about and discuss with a concrete 3 line IR testcase than this

Ok, so here it is:

```
  %cmp1 = fcmp fast ogt double %sub, 0.000000e+00
  %add1 = fadd fast double %v1, %sub
  %v1.1 = select nsz i1 %cmp1, double %add1, double %v1
```

without this commit, it is transformed into:

```
  %cmp1 = fcmp fast ogt double %sub, 0.000000e+00
  %add1 = select nsz i1 %cmp1, double %sub, double 0.000000e+00
  %v1.1 = fadd fast double %add1, %v1
```

giving it some more context:

```
--- fun1.ll     2024-10-22 15:21:01.291767219 +0100
+++ fun1.opt.ll 2024-10-22 15:24:15.400736173 +0100
@@ -1,12 +1,12 @@
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
 target triple = "aarch64-unknown-linux-gnu"

 @v0 = global double 0.000000e+00

 define void @fun(double %v1, double %sub) {
   %cmp1 = fcmp fast ogt double %sub, 0.000000e+00
-  %add1 = fadd fast double %v1, %sub
-  %v1.1 = select nsz i1 %cmp1, double %add1, double %v1
+  %add1 = select nsz i1 %cmp1, double %sub, double 0.000000e+00
+  %v1.1 = fadd fast double %add1, %v1
   store double %v1.1, ptr @v0, align 8
   ret void
 }
```


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


More information about the llvm-commits mailing list