llvm-6502/test/Transforms/ConstantHoisting/X86/phi.ll
Juergen Ributzka 8ebaf63750 [Constant Hoisting] Change the algorithm to only track constants for instructions.
Originally the algorithm would search for expensive constants and track their
users, which could be instructions and constant expressions. This change only
tracks the constants for instructions, but constant expressions are indirectly
covered too. If an operand is an constant expression, then we look through the
expression to find anny expensive constants.

The algorithm keep now track of the instruction and the operand index where the
constant is used. This allows more precise hoisting of constant materialization
code for PHI instructions, because we only hoist to the basic block of the
incoming operand. Before we had to find the idom of all PHI operands and hoist
the materialization code there.

This also makes updating of instructions easier. Before we had to keep track of
the original constant, find it in the instructions, and then replace it. Now we
can just simply update the operand.

Related to <rdar://problem/16381500>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204433 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-21 06:04:36 +00:00

71 lines
2.1 KiB
LLVM

; RUN: opt -S -consthoist < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"
; PR18626
define i8* @test1(i1 %cmp, i64* %tmp) {
entry:
call void @foo(i8* inttoptr (i64 68719476735 to i8*))
br i1 %cmp, label %if.end, label %return
if.end: ; preds = %bb1
call void @foo(i8* inttoptr (i64 68719476736 to i8*))
br label %return
return:
%retval.0 = phi i8* [ null, %entry ], [ inttoptr (i64 68719476736 to i8*), %if.end ]
store i64 1172321806, i64* %tmp
ret i8* %retval.0
; CHECK-LABEL: @test1
; CHECK: if.end:
; CHECK: %const_mat = add i64 %const, 1
; CHECK-NEXT: %1 = inttoptr i64 %const_mat to i8*
; CHECK: return:
; CHECK-NEXT: %retval.0 = phi i8* [ null, %entry ], [ inttoptr (i64 68719476736 to i8*), %if.end ]
}
define void @test2(i1 %cmp, i64** %tmp) {
entry:
call void @foo(i8* inttoptr (i64 68719476736 to i8*))
br i1 %cmp, label %if.end, label %return
if.end: ; preds = %bb1
call void @foo(i8* inttoptr (i64 68719476736 to i8*))
br label %return
return:
store i64* inttoptr (i64 68719476735 to i64*), i64** %tmp
ret void
; CHECK-LABEL: @test2
; CHECK: return:
; CHECK-NEXT: %const_mat = add i64 %const, -1
; CHECK-NEXT: inttoptr i64 %const_mat to i64*
}
declare void @foo(i8*)
; PR18768
define i32 @test3(i1 %c) {
entry:
br i1 %c, label %if.then, label %if.end3
if.then: ; preds = %entry
br label %if.end3
if.end3: ; preds = %if.then, %entry
%d.0 = phi i32* [ inttoptr (i64 985162435264511 to i32*), %entry ], [ null, %if.then ]
%cmp4 = icmp eq i32* %d.0, inttoptr (i64 985162435264511 to i32*)
%cmp6 = icmp eq i32* %d.0, inttoptr (i64 985162418487296 to i32*)
%or = or i1 %cmp4, %cmp6
br i1 %or, label %if.then8, label %if.end9
if.then8: ; preds = %if.end3
ret i32 1
if.end9: ; preds = %if.then8, %if.end3
ret i32 undef
}