[all-commits] [llvm/llvm-project] db7a87: [SimpleLoopUnswitch] Collect either logical ANDs/O...

Florian Hahn via All-commits all-commits at lists.llvm.org
Fri May 6 01:50:36 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: db7a87ed4fa79a7c366438ae62d8a1088a11f29c
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2022-05-06 (Fri, 06 May 2022)

  Changed paths:
    M llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-invariant-select-bug.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-freeze-individual-conditions.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-logical-and-or.ll

  Log Message:
  [SimpleLoopUnswitch] Collect either logical ANDs/ORs but not both.

After D97756, collectHomogenousInstGraphLoopInvariants may collect
conditions for both logical ANDs and logical ORs in case the root is a
select that matches both logical AND & OR.

This means the function won't return invariant values of either AND/OR
chains, but both. This can result in incorrect transformations.

See llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-logical-and-or.ll.
Without the patch, Alive2 rejects the modified tests with:
    Source and target don't have the same return domain.

Note that this also applies to the test case added in D97756
(@test_partial_condition_unswitch_or_select). We can't unswitch on
%cond6, because the graph leading to it contains and AND and an OR.

This only fixes trivial unswitching for now, but a similar problem
likely exists with non-trivial unswitching.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D124526

More information about the All-commits mailing list