From e2d437148ae37c9fbafe74b61cb4a9d81388af1b Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 11 Mar 2014 09:36:48 +0000 Subject: GVN: merge overflow intrinsics with non-overflow instructions. When an overflow intrinsic is followed by a non-overflow instruction, replace the latter with an extract. For example: %sadd = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) %sadd3 = add i32 %a, %b Here the add statement will be replaced by an extract. When an overflow intrinsic follows a non-overflow instruction, a clone of the intrinsic is inserted before the normal instruction, which makes it the same as the previous case. Subsequent runs of GVN can then clean up the duplicate instructions and insert the extract. This fixes PR8817. llvm-svn: 203553 --- llvm/test/Transforms/GVN/overflow.ll | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 llvm/test/Transforms/GVN/overflow.ll (limited to 'llvm/test/Transforms/GVN/overflow.ll') diff --git a/llvm/test/Transforms/GVN/overflow.ll b/llvm/test/Transforms/GVN/overflow.ll new file mode 100644 index 00000000000..4d5ac66dc3f --- /dev/null +++ b/llvm/test/Transforms/GVN/overflow.ll @@ -0,0 +1,43 @@ +; RUN: opt -S -gvn < %s | FileCheck %s + +define i32 @sadd1(i32 %a, i32 %b) #0 { +; CHECK-LABEL: @sadd1( +entry: + %sadd = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) + %cmp = extractvalue { i32, i1 } %sadd, 1 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + ret i32 42 + +if.end: ; preds = %entry + %sadd3 = add i32 %a, %b + ret i32 %sadd3 +; CHECK-NOT: add i32 %a, %b +; CHECK: %sadd3.repl = extractvalue { i32, i1 } %sadd, 0 +; CHECK: ret i32 %sadd3.repl +} + +define i32 @sadd2(i32 %a, i32 %b) #0 { +entry: + %sadd3 = add i32 %a, %b + %sadd = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) + %cmp = extractvalue { i32, i1 } %sadd, 1 + br i1 %cmp, label %if.then, label %if.end +; CHECK-NOT: %sadd3 = add i32 %a, %b +; CHECK: %sadd.repl = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) +; CHECK-NOT: %sadd = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) +; CHECK: %sadd3.repl = extractvalue { i32, i1 } %sadd.repl, 0 + +if.then: ; preds = %entry + %sadd4 = add i32 %sadd3, 1 + ret i32 %sadd4 +; CHECK: %sadd4 = add i32 %sadd3.repl, 1 + +if.end: ; preds = %entry + ret i32 %sadd3 +; CHECK: ret i32 %sadd3.repl +} + + +declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone -- cgit v1.2.3