# HG changeset patch # User S.Bharadwaj Yadavalli # Date 1390963049 18000 # Node ID e99fccb039265e1827f06633ee8c7a5f6725f05d # Parent 9e7acc9cad8e0ab686e21256c716f116775afc3a Fix incorrect code generation for conditional branch instructions. Reenable ControlPTXTest. diff -r 9e7acc9cad8e -r e99fccb03926 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java Tue Jan 28 23:38:22 2014 +0100 +++ b/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java Tue Jan 28 21:37:29 2014 -0500 @@ -397,13 +397,17 @@ } // Checkstyle: stop method name check - public final void bra(String tgt, int pred) { + /* + * Emit conditional branch to target 'tgt' guarded by predicate register 'pred' whose state is + * tested to be 'predCheck'. + */ + public final void bra(String tgt, int pred, boolean predCheck) { assert pred >= 0; if (tgt.equals("?")) { Thread.dumpStack(); } - emitString("@%p" + pred + " " + "bra" + " " + tgt + ";"); + emitString("@" + (predCheck ? "%p" : "!%p") + pred + " " + "bra" + " " + tgt + ";"); } public final void bra(String src) { diff -r 9e7acc9cad8e -r e99fccb03926 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java Tue Jan 28 23:38:22 2014 +0100 +++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java Tue Jan 28 21:37:29 2014 -0500 @@ -26,18 +26,26 @@ public class ControlPTXTest extends PTXTest { - @Ignore("[CUDA] *** Error (status=702): Synchronize kernel") @Test - public void testControl() { + public void testControl1() { test("testLoop", 42); test("testSwitchDefault1I", 3); test("testSwitch1I", 2); test("testIfElse1I", 222); test("testIfElse2I", 19, 64); + } - test("testIntegerTestBranch2I", 0xff00, 0x00ff); + @Test + public void testControl2() { compileKernel("testStatic"); compileKernel("testCall"); + } + + @Ignore("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options") + @Test + public void testControl3() { + // test("testIntegerTestBranch2I", 0xff00, 0x00ff); + compileKernel("testIntegerTestBranch2I"); compileKernel("testLookupSwitch1I"); } diff -r 9e7acc9cad8e -r e99fccb03926 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java Tue Jan 28 23:38:22 2014 +0100 +++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java Tue Jan 28 21:37:29 2014 -0500 @@ -86,9 +86,9 @@ @Override public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { if (crb.isSuccessorEdge(trueDestination)) { - masm.bra(masm.nameOf(falseDestination.label()), predRegNum); + masm.bra(masm.nameOf(falseDestination.label()), predRegNum, false); } else { - masm.bra(masm.nameOf(trueDestination.label())); + masm.bra(masm.nameOf(trueDestination.label()), predRegNum, true); if (!crb.isSuccessorEdge(falseDestination)) { masm.jmp(falseDestination.label()); } @@ -238,7 +238,7 @@ default: throw new GraalInternalError("switch only supported for int, long and object"); } - masm.bra(masm.nameOf(target), predRegNum); + masm.bra(masm.nameOf(target), predRegNum, true); } }; strategy.run(closure); @@ -281,7 +281,7 @@ // Jump to default target if index is not within the jump table if (defaultTarget != null) { - masm.bra(masm.nameOf(defaultTarget.label()), predRegNum); + masm.bra(masm.nameOf(defaultTarget.label()), predRegNum, true); } // address of jump table