diff options
author | Arnold Schwaighofer <aschwaighofer@apple.com> | 2013-12-17 01:11:01 +0000 |
---|---|---|
committer | Arnold Schwaighofer <aschwaighofer@apple.com> | 2013-12-17 01:11:01 +0000 |
commit | 50b8302c5512cbca383e5c09e9f6ef240d149ce2 (patch) | |
tree | 25b10bdbf94b2623e0395b2828ef0e024afa889b /llvm/test/Transforms/LoopVectorize | |
parent | 769c04ea359e555bd60ae50763427d645d0a396e (diff) | |
download | bcm5719-llvm-50b8302c5512cbca383e5c09e9f6ef240d149ce2.tar.gz bcm5719-llvm-50b8302c5512cbca383e5c09e9f6ef240d149ce2.zip |
LoopVectorizer: Don't if-convert constant expressions that can trap
A phi node operand or an instruction operand could be a constant expression that
can trap (division). Check that we don't vectorize such cases.
PR16729
radar://15653590
llvm-svn: 197449
Diffstat (limited to 'llvm/test/Transforms/LoopVectorize')
-rw-r--r-- | llvm/test/Transforms/LoopVectorize/if-conversion.ll | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoopVectorize/if-conversion.ll b/llvm/test/Transforms/LoopVectorize/if-conversion.ll index 88e56b2457d..dbe0243a811 100644 --- a/llvm/test/Transforms/LoopVectorize/if-conversion.ll +++ b/llvm/test/Transforms/LoopVectorize/if-conversion.ll @@ -106,3 +106,66 @@ for.end: ; preds = %for.inc, %entry ret i32 %sum.0.lcssa } +@a = common global [1 x i32*] zeroinitializer, align 8 +@c = common global i32* null, align 8 + +; We use to if convert this loop. This is not safe because there is a trapping +; constant expression. +; PR16729 + +; CHECK-LABEL: trapping_constant_expression +; CHECK-NOT: or <4 x i32> + +define i32 @trapping_constant_expression() { +entry: + br label %for.body + +for.body: + %inc3 = phi i32 [ 0, %entry ], [ %inc, %cond.end ] + %or2 = phi i32 [ 0, %entry ], [ %or, %cond.end ] + br i1 icmp eq (i32** getelementptr inbounds ([1 x i32*]* @a, i64 0, i64 0), i32** @c), label %cond.false, label %cond.end + +cond.false: + br label %cond.end + +cond.end: + %cond = phi i32 [ sdiv (i32 1, i32 zext (i1 icmp eq (i32** getelementptr inbounds ([1 x i32*]* @a, i64 0, i64 0), i32** @c) to i32)), %cond.false ], [ 0, %for.body ] + %or = or i32 %or2, %cond + %inc = add nsw i32 %inc3, 1 + %cmp = icmp slt i32 %inc, 128 + br i1 %cmp, label %for.body, label %for.end + +for.end: + ret i32 %or +} + +; Neither should we if-convert if there is an instruction operand that is a +; trapping constant expression. +; PR16729 + +; CHECK-LABEL: trapping_constant_expression2 +; CHECK-NOT: or <4 x i32> + +define i32 @trapping_constant_expression2() { +entry: + br label %for.body + +for.body: + %inc3 = phi i32 [ 0, %entry ], [ %inc, %cond.end ] + %or2 = phi i32 [ 0, %entry ], [ %or, %cond.end ] + br i1 icmp eq (i32** getelementptr inbounds ([1 x i32*]* @a, i64 0, i64 0), i32** @c), label %cond.false, label %cond.end + +cond.false: + %cond.1 = or i32 %inc3, sdiv (i32 1, i32 zext (i1 icmp eq (i32** getelementptr inbounds ([1 x i32*]* @a, i64 0, i64 0), i32** @c) to i32)) + br label %cond.end + +cond.end: + %cond = phi i32 [ %cond.1, %cond.false ], [ %inc3, %for.body ] + %or = or i32 %or2, %cond + %inc = add nsw i32 %inc3, 1 + %cmp = icmp slt i32 %inc, 128 + br i1 %cmp, label %for.body, label %for.end + +for.end: + ret i32 %or +} |