[PATCH] D151758: [Reassociate] Group select of constants together with constants

Mikhail Gudim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 31 04:59:52 PDT 2023


mgudim added inline comments.


================
Comment at: llvm/test/Transforms/Reassociate/select-of-constants.ll:19
+  ret i32 %add_
+}
----------------
nikic wrote:
> This test produces the same result before and after your patch (https://llvm.godbolt.org/z/v6oe486Mc).
The output after reassociate is:

```
define dso_local signext i32 @select_of_constants(i32 noundef signext %a, i1 %c) {
entry:
  %select_ = select i1 %c, i32 8, i32 2
  %add4 = add i32 %select_, 4  ; note that now we add 4 to %select_
  %add_ = add i32 %add4, %a
  ret i32 %add_
}

```

So basically, the input corresponds to this expression: `%select_ + (%a + 4)` and output corresponds to this: `(%select + 4) + %a`. This allows `InstCombine` to "swallow` addition of 4 into the select. At the end of opt we'll have:

```
define dso_local signext i32 @select_of_constants(i32 noundef signext %a, i1 %c) local_unnamed_addr #0 {
entry:
  %add4 = select i1 %c, i32 12, i32 6
  %add_ = add i32 %add4, %a
  ret i32 %add_
}

```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151758/new/

https://reviews.llvm.org/D151758



More information about the llvm-commits mailing list