diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2bec9cb82ae59aa0fe1604b9b0a2f75c2336bd9c..c819d1d0636a8579050763eb565596836ffac82a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
 2012-01-30  Jakub Jelinek  <jakub@redhat.com>
 
+	PR tree-optimization/52046
+	* tree-vect-patterns.c (check_bool_pattern): Give up if
+	a comparison could throw.
+
 	PR debug/52048
 	* tree-ssa-tail-merge.c (local_def): Ignore debug uses.
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e543e9a630a0135927f969cc64a58b359dd41657..36dab8f112b126d325ec13ff9674ab91b7a02dd1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2012-01-30  Jakub Jelinek  <jakub@redhat.com>
 
+	PR tree-optimization/52046
+	* gcc.dg/pr52046.c: New test.
+
 	PR debug/52048
 	* g++.dg/other/pr52048.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr52046.c b/gcc/testsuite/gcc.dg/pr52046.c
new file mode 100644
index 0000000000000000000000000000000000000000..e72061f9908e2a5550b9ff99f5ae4823bd11d23c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr52046.c
@@ -0,0 +1,14 @@
+/* PR tree-optimization/52046 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fexceptions -fnon-call-exceptions" } */
+
+extern float a[], b[], c[], d[];
+extern int k[];
+
+void
+foo (void)
+{
+  int i;
+  for (i = 0; i < 1024; ++i)
+    k[i] = (a[i] < b[i]) | (c[i] < d[i]);
+}
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 34ac2e5329f691d66dc839582eabf31806ae3861..f63b4e593cc27aad48695b2abb35362af1fd1fd2 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -1,5 +1,5 @@
 /* Analysis Utilities for Loop Vectorization.
-   Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
+   Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Contributed by Dorit Nuzman <dorit@il.ibm.com>
 
@@ -1967,6 +1967,11 @@ check_bool_pattern (tree var, loop_vec_info loop_vinfo)
 	{
 	  tree vecitype, comp_vectype;
 
+	  /* If the comparison can throw, then is_gimple_condexpr will be
+	     false and we can't make a COND_EXPR/VEC_COND_EXPR out of it.  */
+	  if (stmt_could_throw_p (def_stmt))
+	    return false;
+
 	  comp_vectype = get_vectype_for_scalar_type (TREE_TYPE (rhs1));
 	  if (comp_vectype == NULL_TREE)
 	    return false;