@@ -5287,9 +5287,20 @@ OptimizeLongfill(IRList *irl) {
52875287 IR * prevset ;
52885288 int32_t setval ;
52895289 if (IsDummy (ir )) continue ;
5290- if (ir -> opc == OPC_CALL && !CondIsSubset (COND_C ,ir -> cond ) && !strcmp (ir -> dst -> name ,"builtin_longfill_" )
5290+ if (ir -> opc == OPC_CALL && !strcmp (ir -> dst -> name ,"builtin_longfill_" )
5291+ && CondIsSubset (ir -> cond , (IRCond )((ir -> cond >>2 )|COND_NC ))
52915292 && (prevset = FindPrevSetterForReplace (ir ,GetArgReg (1 )))
52925293 && isConstMove (prevset ,& setval )) {
5294+ //
5295+ // The CondIsSubset(ir->cond, (ir->cond>>2)|COND_NC)
5296+ // bit above requires explanation:
5297+ // Some conditions can't be combined with COND_NC
5298+ // These are ones where there are some condition states (of the 4
5299+ // possible) that execute the original condition, but after clearing
5300+ // C do not necessarily execute the combined condition.
5301+ // The bitwise operation is somewhat mindbboggling but Ada
5302+ // tested it with a script.
5303+ //
52935304 int addr = ir -> addr ; // Some opts require addresses to be sorta-correct;
52945305 // Since we replace a funccall, we can clobber flags and args
52955306 IR * sub = NewIR (OPC_SUB );
@@ -5299,7 +5310,6 @@ OptimizeLongfill(IRList *irl) {
52995310 sub -> addr = addr ;
53005311 sub -> cond = ir -> cond ;
53015312 IR * setq = NewIR (OPC_SETQ );
5302- setq -> cond = COND_NC ;
53035313 setq -> dst = GetArgReg (2 );
53045314 setq -> cond = (IRCond )(COND_NC | ir -> cond );
53055315 setq -> addr = addr ;
0 commit comments