From 51af8a6401eea726d3498e6b2aba456b6af246d6 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Mon, 27 Feb 2023 16:02:21 +0100 Subject: d: vector float comparison doesn't result in 0 or -1 [PR108945] When comparing two vectors, the type of vector was used as the result of the condition result. This meant that for floating point comparisons, each value would either be `0.0' or `-1.0' reinterpreted as an integer, not the expected integral bitmask values `0' and `-1'. Instead, use the comparison type determined by truth_type_for as the result of the comparison. If a reinterpret is later required by the final conversion for generating CmpExp, it is still only going to reinterpret one integer kind as another. PR d/108945 gcc/d/ChangeLog: * d-codegen.cc (build_boolop): Evaluate vector comparison as the truth_type_for vector type. gcc/testsuite/ChangeLog: * gdc.dg/pr108945.d: New test. --- gcc/d/d-codegen.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gcc/d/d-codegen.cc') diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 0e8e073..5a04192 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1453,13 +1453,12 @@ build_boolop (tree_code code, tree arg0, tree arg1) { /* Build a vector comparison. VEC_COND_EXPR ; */ - tree type = TREE_TYPE (arg0); - tree cmptype = truth_type_for (type); + tree cmptype = truth_type_for (TREE_TYPE (arg0)); tree cmp = fold_build2_loc (input_location, code, cmptype, arg0, arg1); - return fold_build3_loc (input_location, VEC_COND_EXPR, type, cmp, - build_minus_one_cst (type), - build_zero_cst (type)); + return fold_build3_loc (input_location, VEC_COND_EXPR, cmptype, cmp, + build_minus_one_cst (cmptype), + build_zero_cst (cmptype)); } if (code == EQ_EXPR || code == NE_EXPR) -- cgit v1.1