[llvm-bugs] [Bug 50228] New: remove the phi requirement that each predecessor edge has an incoming value

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 5 05:58:46 PDT 2021


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

            Bug ID: 50228
           Summary: remove the phi requirement that each predecessor edge
                    has an incoming value
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Support Libraries
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org

Splitting from bug 46721 - this is invalid IR:

define i64 @func(i64 %x) {
L0:
        switch i64 %x, label %L2 [
                i64 1, label %L1
                i64 4, label %L2
                i64 6, label %L2
        ]
L1:
        br label %L2
L2:
        %r = phi i64 [%x, %L0], [42, %L1]
        ret i64 %r
}

$ opt -verify phi.ll -S
PHINode should have one entry for each predecessor of its parent basic block!
  %r = phi i64 [ %x, %L0 ], [ %x, %L0 ], [ 42, %L1 ]
opt: phi.ll: error: input module is broken!

--------------------------------------------------------------------------

To make it valid, we need to repeat the incoming value from %L0 three times:
once for the 'default' edge of the switch, once for case 4, and once for case
6:

define i64 @func(i64 %x) {
L0:
  switch i64 %x, label %L2 [
    i64 1, label %L1
    i64 4, label %L2
    i64 6, label %L2
  ]

L1:                                               ; preds = %L0
  br label %L2

L2:                                               ; preds = %L1, %L0, %L0, %L0
  %r = phi i64 [ %x, %L0 ], [ %x, %L0 ], [ %x, %L0 ], [ 42, %L1 ]
  ret i64 %r
}

--------------------------------------------------------------------------

This is confusing and may cause problems for other passes as they
simplify/reduce code (SLP had a relatively recent bug report because of this).

Can we accept the reduced form as valid IR (and canonicalize to it)?

-- 
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/20210505/effcfd5d/attachment.html>


More information about the llvm-bugs mailing list