[llvm-bugs] [Bug 34228] New: Optimizer doesn't eliminate select with two equivalent operands

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 17 20:18:41 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34228

            Bug ID: 34228
           Summary: Optimizer doesn't eliminate select with two equivalent
                    operands
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: me at manueljacob.de
                CC: llvm-bugs at lists.llvm.org

The following transformation doesn't happen:

%shared = add i64 %x, %y
%r1 = select i1 %c1, i64 %shared, i64 %x
%r2 = select i1 %c2, i64 %shared, i64 %y
%tmp = select i1 %c2, i64 %x, i64 0
%r2_eq1 = add i64 %tmp, %y
%r2_eq2 = select i1 %zzz, i64 %r2, i64 %r2_eq1
%r = add i64 %r1, %r2_eq2
  =>
%shared = add i64 %x, %y
%r1 = select i1 %c1, i64 %shared, i64 %x
%r2 = select i1 %c2, i64 %shared, i64 %y
%r = add i64 %r1, %r2

http://rise4fun.com/Alive/IOS5

InstCombine can do the following canonicalization (see comment in
`getSelectFoldableOperands()`):

%shared = add i64 %x, %y
%r2 = select i1 %c2, i64 %shared, i64 %y
  =>
%tmp = select i1 %c2, i64 %x, i64 0
%r2 = add i64 %tmp, %y

But in this case the canonicalization doesn't happen, because %shared has two
uses.  Note that %r2_eq1 actually is the canonical form of %r2.  Further
canonicalization of either %r2 or %r2_eq1 won't happen.  This is why the
optimizer doesn't see that %r2_eq2 selects between two equivalent operands (and
is therefore equal to %r2).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170818/320e0e8d/attachment.html>


More information about the llvm-bugs mailing list