[all-commits] [llvm/llvm-project] c75a0f: [InstCombine] Optimize compares with multiple sele...

tejas-amd via All-commits all-commits at lists.llvm.org
Fri May 26 07:05:49 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c75a0f5a9a368b6ca3ec0a696f2a934e8dd0e5bb
      https://github.com/llvm/llvm-project/commit/c75a0f5a9a368b6ca3ec0a696f2a934e8dd0e5bb
  Author: Tejas Joshi <TejasSanjay.Joshi at amd.com>
  Date:   2023-05-26 (Fri, 26 May 2023)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    M llvm/test/Transforms/InstCombine/icmp-with-selects.ll

  Log Message:
  -----------
  [InstCombine] Optimize compares with multiple selects as operands

In case of a comparison with two select instructions having the same
condition, check whether one of the resulting branches can be simplified.
If so, just compare the other branch and select the appropriate result.
For example:

    %tmp1 = select i1 %cmp, i32 %y, i32 %x
    %tmp2 = select i1 %cmp, i32 %z, i32 %x
    %cmp2 = icmp slt i32 %tmp2, %tmp1

The icmp will result false for the false value of selects and the result
will depend upon the comparison of true values of selects if %cmp is
true. Thus, transform this into:

    %cmp = icmp slt i32 %y, %z
    %sel = select i1 %cond, i1 %cmp, i1 false

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




More information about the All-commits mailing list