[all-commits] [llvm/llvm-project] 5cc934: [InstCombine] Add reduced test for PR 71330; NFC

goldsteinn via All-commits all-commits at lists.llvm.org
Thu Nov 9 14:37:11 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5cc9347aa3f13e3bcea92640771f6352e2181ef4
      https://github.com/llvm/llvm-project/commit/5cc9347aa3f13e3bcea92640771f6352e2181ef4
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-09 (Thu, 09 Nov 2023)

  Changed paths:
    A llvm/test/Transforms/InstCombine/pr71330.ll

  Log Message:
  -----------
  [InstCombine] Add reduced test for PR 71330; NFC


  Commit: 9ef829097bbc4cf908698e3891af11a154e1d3e2
      https://github.com/llvm/llvm-project/commit/9ef829097bbc4cf908698e3891af11a154e1d3e2
  Author: Noah Goldstein <goldstein.w.n at gmail.com>
  Date:   2023-11-09 (Thu, 09 Nov 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/pr71330.ll

  Log Message:
  -----------
  [InstCombine] Fix buggy transform in `foldNestedSelects`; PR 71330

The bug is that `IsAndVariant` is used to assume which arm in the
select the output `SelInner` should be placed but match the inner
select condition with `m_c_LogicalOp`. With fully simplified ops, this
works fine, but its possible if the select condition is not
simplified, for it match both `LogicalAnd` and `LogicalOr` i.e `select
true, true, false`.

In PR71330 for example, the issue occurs in the following IR:
```
define i32 @bad() {
  %..i.i = select i1 false, i32 0, i32 3
  %brmerge = select i1 true, i1 true, i1 false
  %not.cmp.i.i.not = xor i1 true, true
  %.mux = zext i1 %not.cmp.i.i.not to i32
  %retval.0.i.i = select i1 %brmerge, i32 %.mux, i32 %..i.i
  ret i32 %retval.0.i.i
}
```

When simplifying:
```
%retval.0.i.i = select i1 %brmerge, i32 %.mux, i32 %..i.i
```

We end up matching `%brmerge` as `LogicalAnd` for `IsAndVariant`, but
the inner select (`%..i.i`) condition which is `false` with
`LogicalOr`.

Closes #71489


Compare: https://github.com/llvm/llvm-project/compare/10a9e7442c4c...9ef829097bbc


More information about the All-commits mailing list