From 5cfc91c9a524efb027e6a639ef69fd0ca8911389 Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Sat, 22 Mar 2014 01:49:27 +0000 Subject: [Constant Hoisting] Fix multiple entries for the same basic block in PHI nodes. A PHI node usually has only one value/basic block pair per incoming basic block. In the case of a switch statement it is possible that a following PHI node may have more than one such pair per incoming basic block. E.g.: %0 = phi i64 [ 123456, %case2 ], [ 654321, %Entry ], [ 654321, %Entry ] This is valid and the verfier doesn't complain, because both values are the same. Constant hoisting materializes the constant for each operand separately and the value is still the same, but the variable names have changed. As a result the verfier can't recognize anymore that they are the same value and complains. This fix adds special update code for PHI node in constant hoisting to prevent this corner case. This fixes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204537 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/ConstantHoisting/X86/phi.ll | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/Transforms/ConstantHoisting') diff --git a/test/Transforms/ConstantHoisting/X86/phi.ll b/test/Transforms/ConstantHoisting/X86/phi.ll index 7134723f61..086df14047 100644 --- a/test/Transforms/ConstantHoisting/X86/phi.ll +++ b/test/Transforms/ConstantHoisting/X86/phi.ll @@ -68,3 +68,49 @@ if.then8: ; preds = %if.end3 if.end9: ; preds = %if.then8, %if.end3 ret i32 undef } + +; +define i64 @switch_test1(i64 %a) { +; CHECK-LABEL: @switch_test1 +; CHECK: %0 = phi i64 [ %const, %case2 ], [ %const_mat, %Entry ], [ %const_mat, %Entry ] +Entry: + %sel = add i64 %a, 4519019440 + switch i64 %sel, label %fail [ + i64 462, label %continuation + i64 449, label %case2 + i64 443, label %continuation + ] + +case2: + br label %continuation + +continuation: + %0 = phi i64 [ 4519019440, %case2 ], [ 4519019460, %Entry ], [ 4519019460, %Entry ] + ret i64 0; + +fail: + ret i64 -1; +} + +define i64 @switch_test2(i64 %a) { +; CHECK-LABEL: @switch_test2 +; CHECK: %2 = phi i64* [ %1, %case2 ], [ %0, %Entry ], [ %0, %Entry ] +Entry: + %sel = add i64 %a, 4519019440 + switch i64 %sel, label %fail [ + i64 462, label %continuation + i64 449, label %case2 + i64 443, label %continuation + ] + +case2: + br label %continuation + +continuation: + %0 = phi i64* [ inttoptr(i64 4519019440 to i64*), %case2 ], [ inttoptr(i64 4519019460 to i64*), %Entry ], [ inttoptr(i64 4519019460 to i64*), %Entry ] + ret i64 0; + +fail: + ret i64 -1; +} + -- cgit v1.2.3