llvm-mirror/test/Transforms/GVN/pre-compare.ll
David Blaikie 3ea2df7c7b [opaque pointer type] Add textual IR support for explicit type parameter to gep operator
Similar to gep (r230786) and load (r230794) changes.

Similar migration script can be used to update test cases, which
successfully migrated all of LLVM and Polly, but about 4 test cases
needed manually changes in Clang.

(this script will read the contents of stdin and massage it into stdout
- wrap it in the 'apply.sh' script shown in previous commits + xargs to
apply it over a large set of test cases)

import fileinput
import sys
import re

rep = re.compile(r"(getelementptr(?:\s+inbounds)?\s*\()((<\d*\s+x\s+)?([^@]*?)(|\s*addrspace\(\d+\))\s*\*(?(3)>)\s*)(?=$|%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|zeroinitializer|<|\[\[[a-zA-Z]|\{\{)", re.MULTILINE | re.DOTALL)

def conv(match):
  line = match.group(1)
  line += match.group(4)
  line += ", "
  line += match.group(2)
  return line

line = sys.stdin.read()
off = 0
for match in re.finditer(rep, line):
  sys.stdout.write(line[off:match.start()])
  sys.stdout.write(conv(match))
  off = match.end()
sys.stdout.write(line[off:])

llvm-svn: 232184
2015-03-13 18:20:45 +00:00

69 lines
2.3 KiB
LLVM

; RUN: opt -gvn -S < %s | FileCheck %s
; C source:
;
; void f(int x) {
; if (x != 1)
; puts (x == 2 ? "a" : "b");
; for (;;) {
; puts("step 1");
; if (x == 2)
; continue;
; printf("step 2: %d\n", x);
; }
; }
;
; If we PRE %cmp3, CodeGenPrepare won't be able to sink the compare down to its
; uses, and we are forced to keep both %x and %cmp3 in registers in the loop.
;
; It is just as cheap to recompute the icmp against %x as it is to compare a
; GPR against 0. On x86-64, the br i1 %cmp3 becomes:
;
; testb %r12b, %r12b
; jne LBB0_3
;
; The sunk icmp is:
;
; cmpl $2, %ebx
; je LBB0_3
;
; This is just as good, and it doesn't require a separate register.
;
; CHECK-NOT: phi i1
@.str = private unnamed_addr constant [2 x i8] c"a\00", align 1
@.str1 = private unnamed_addr constant [2 x i8] c"b\00", align 1
@.str2 = private unnamed_addr constant [7 x i8] c"step 1\00", align 1
@.str3 = private unnamed_addr constant [12 x i8] c"step 2: %d\0A\00", align 1
define void @f(i32 %x) noreturn nounwind uwtable ssp {
entry:
%cmp = icmp eq i32 %x, 1
br i1 %cmp, label %for.cond.preheader, label %if.then
if.then: ; preds = %entry
%cmp1 = icmp eq i32 %x, 2
%cond = select i1 %cmp1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str1, i64 0, i64 0)
%call = tail call i32 @puts(i8* %cond) nounwind
br label %for.cond.preheader
for.cond.preheader: ; preds = %entry, %if.then
%cmp3 = icmp eq i32 %x, 2
br label %for.cond
for.cond: ; preds = %for.cond.backedge, %for.cond.preheader
%call2 = tail call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str2, i64 0, i64 0)) nounwind
br i1 %cmp3, label %for.cond.backedge, label %if.end5
if.end5: ; preds = %for.cond
%call6 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str3, i64 0, i64 0), i32 %x) nounwind
br label %for.cond.backedge
for.cond.backedge: ; preds = %if.end5, %for.cond
br label %for.cond
}
declare i32 @puts(i8* nocapture) nounwind
declare i32 @printf(i8* nocapture, ...) nounwind