https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105030
--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to HaoChen Gui from comment #11) > I tested C source code with Ofast. The Ofast enables data store race. It > should do store motion but it fails. The problem is on cselim pass. It does > conditional store replacement. The 'atemp' is converted to its alias set - > 'MEM <double> [(void *)&atemp]' in the if-else blocks and remains untouch > out of the if-else. > > atemp.0_5 = atemp; > if (_4 < atemp.0_5) > goto <bb 5>; [50.00%] > else > goto <bb 4>; [50.00%] > > <bb 4> [local count: 477815113]: > cstore_18 = MEM <double> [(void *)&atemp]; > > <bb 5> [local count: 955630225]: > # cstore_17 = PHI <cstore_18(4), _4(3)> > MEM <double> [(void *)&atemp] = cstore_17; > > Then in lim2 pass, it thinks 'atemp' and 'MEM <double> [(void *)&atemp]' are > independent. So the store can't be moved out. > > Memory reference 1: *_3 > Memory reference 2: atemp > Memory reference 3: MEM <double> [(void *)&atemp] > Querying dependency of refs 3 and 1: independent. > Querying dependency of refs 3 and 2: dependent. > Querying SM WAR dependencies of ref 3 in loop 1: dependent > > I wonder if 'atemp' is equivalent to 'MEM <double> [(void *)&atemp]'. Why we > shall use alias-set zero in cselim pass. > > /* Make both store and load use alias-set zero as we have to > deal with the case of the store being a conditional change > of the dynamic type. */ > > while (handled_component_p (*basep)) > basep = &TREE_OPERAND (*basep, 0); > if (TREE_CODE (*basep) == MEM_REF > || TREE_CODE (*basep) == TARGET_MEM_REF) > TREE_OPERAND (*basep, 1) > = fold_convert (ptr_type_node, TREE_OPERAND (*basep, 1)); > else > *basep = build2 (MEM_REF, TREE_TYPE (*basep), > build_fold_addr_expr (*basep), > build_zero_cst (ptr_type_node)); This is to deal with a more generic case. In this particular case there's a load from atemp always executed when executing the conditional and we could devise some condition under which using the original alias set of the conditional store unconditional is correct (but it's not going to be trivial). Store motion is (unfortunately) tied to "exactly" matching load/store pairs: Memory reference 1: *_3 Memory reference 2: atemp(address-taken) Memory reference 3: MEM <double> [(void *)&atemp(address-taken)] here we have reference 2 and 3 so that will inevitably fail. We already do some "unification" but do not try to merge TBAA info there.