Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Test/Expect/cexec06.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1
35 changes: 35 additions & 0 deletions Test/cexec06.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// a conditional instruction that sets flags must not be folded
// as if it always ran (flexprop issue 118)
//
#include <stdio.h>
#include <propeller.h>

int g; // 0
int seed = 5;

void myexit(int n)
{
putchar(0xff);
putchar(0x0);
putchar(n);
waitcnt(getcnt() + 40000000);
#ifdef __OUTPUT_BYTECODE__
_cogstop(_cogid());
#else
__asm {
cogid n
cogstop n
}
#endif
}

void main() {
int v = seed;
_Bool f = (v < v); // false, and the optimizer can tell
int r = (12 != g) || f; // 1, since g is 0
_Bool f2 = (seed > 100); // false, and the optimizer cannot tell
int r2 = (12 != g) || f2;
printf("%d %d\n", r, r2);
myexit(0);
}
5 changes: 5 additions & 0 deletions backends/asm/optimize_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,11 @@ TransformConstDst(IRList *irl, IR *ir, Operand *imm)
}
if (InstrSetsAnyFlags(ir)) {
int condchange = 0;
if (ir->cond != COND_TRUE) {
// a conditional instruction sets the flags only where it runs,
// so what they are after it is not known
return 0;
}
if (!ApplyConditionAfter(irl,ir, cval, val1, &condchange)) {
return condchange; // Couldn't apply condition :(
}
Expand Down