Skip to content

Commit ac16eef

Browse files
committed
Fix latent bug in OptimizeLongfill
1 parent 3ef746c commit ac16eef

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version 7.4.0
33
- Fixed compile time calculations of QLOG and QEXP (thanks to Ada)
44
- Fixed many incorrect address calculations for Spin2 ^x variables
55
- Improved some nucode peephole optimizations
6+
- Some longfill optimizations and bug fixes (thanks to Ada)
67

78
Version 7.3.0
89
- Allow `__attribute__((packed))` on C structs

backends/asm/optimize_ir.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)