https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114666
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org Status|NEW |ASSIGNED --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Folding statement: _3 = _2 ^ 1; Matching expression match.pd:2835, gimple-match-2.cc:35 Matching expression match.pd:2838, gimple-match-1.cc:66 Matching expression match.pd:2845, gimple-match-2.cc:96 Matching expression match.pd:2243, gimple-match-5.cc:20 Matching expression match.pd:2835, gimple-match-2.cc:35 Matching expression match.pd:2838, gimple-match-1.cc:66 Matching expression match.pd:2845, gimple-match-2.cc:96 Applying pattern match.pd:6795, gimple-match-4.cc:1721 Matching expression match.pd:2243, gimple-match-5.cc:20 Matching expression match.pd:2286, gimple-match-3.cc:23 Matching expression match.pd:2255, gimple-match-4.cc:67 Matching expression match.pd:2243, gimple-match-5.cc:20 Applying pattern match.pd:7103, gimple-match-8.cc:47279 Applying pattern match.pd:5898, gimple-match-8.cc:47191 gimple_simplified to _7 = (long unsigned int) _1; _8 = -_7; _3 = _8 ^ 1; That is wrong. I can't figure out how we got there though. match.pd:6795 is the pattern which does `(convert)a CMP b` into `a CMP (convert)b` which I assume VRP does `_3 == 0 ? 1 : -2u` which then we get `_1 == 0 ? 1 : -2u` (which seems reasonable) and then we apply match.pd:5898 which gets us to `_1 ? -2u : 1` which seems wrong as not a boolean type nor an one bit unsigned integer. So the problem is with: /* !A ? B : C -> A ? C : B. */ (simplify (cnd (logical_inverted_value truth_valued_p@0) @1 @2) (cnd @0 @2 @1))) which does not check the types correctly for gimple. Note this pattern has been there since 2014. Just been exposed the issue when I added match.pd:7103 in r14-3110-g7fb65f10285124. Let me try to figure out what to do here to fix the issue.