https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:51abfb6a893c87dbf84a33009b6cd6dbd25d66f1 commit r12-2048-g51abfb6a893c87dbf84a33009b6cd6dbd25d66f1 Author: Andrew Pinski <apin...@marvell.com> Date: Tue Jun 29 14:30:34 2021 -0700 Fix 101256: Wrong code due to range incorrect from PHI-OPT So the problem here is that replace_phi_edge_with_variable will copy range information to a already (not newly) defined ssa name. This causes wrong code later on. This fixes the problem by require the new ssa name to be defined in the same bb as the conditional that is about to be deleted. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Changes from v1: * this is a simplification of what was trying to be done before. gcc/ChangeLog: PR tree-optimization/101256 * dbgcnt.def (phiopt_edge_range): New counter. * tree-ssa-phiopt.c (replace_phi_edge_with_variable): Check to make sure the new name is defined in the same bb as the conditional before duplicating range info. Also add debug counter. gcc/testsuite/ChangeLog: PR tree-optimization/101256 * g++.dg/torture/pr101256.C: New test.