A computer implemented method for optimizing quantum circuits, comprising: receiving a netlist representation and building a corresponding directed acyclic graph, DAG, representation from the netlist representation, the netlist representation and the DAG representation containing information about a first list of quantum gates that form the quantum circuits, with the first list of quantum gates including a subcircuit consisting of at least NOT gates, CNOT gates, and Rz(θ) gates that are vertices of the DAG and edges of the DAG encoding input/output relationships of the first list of quantum gates; determining whether control and target qubits of each CNOT gate in the subcircuit are within a termination border to confirm whether there are intermediate Hadamard gates on wires that leave and re-enter the subcircuit; performing, based on the netlist representation and the DAG representation, a phase-polynomial reduction operation on the information about the first list of quantum gates to produce a second list of quantum gates that has functional equivalence to the first list of quantum gates, the phase-polynomial reduction operation including a combining of respective rotations of at least two Rz(θ) gates of the subcircuit from the first list of quantum gates into a resulting Rz(θ) gate of the second list of quantum gates, the at least two Rz(θ) gates from the first list all being applied to a same qubit, and the resulting Rz(θ) gate of the second list being applied to the same qubit as that of the at least two Rz(θ) gates from the first list, wherein each of the Rz(θ) gates is parameterizable by a rotation angle θ that can take any value in a range between 0 and 2π, a number of quantum gates in the second list of quantum gates being smaller than a number of quantum gates in the first list of quantum gates, and the netlist representation and the DAG representation being updated concurrently whenever a reduction in the number of quantum gates in the first list of quantum gates is found as part of the phase-polynomial reduction operation; and generating a new netlist representation containing information about the second list of quantum gates to implement by a quantum computer a quantum circuit comprising the quantum gates of the second list as set out in the new netlist representation. receiving a netlist representation and building a corresponding directed acyclic graph, DAG, representation from the netlist representation, the netlist representation and the DAG representation containing information about a first list of quantum gates that form the quantum circuits, with the first list of quantum gates including a subcircuit consisting of at least NOT gates, CNOT gates, and Rz(θ) gates that are vertices of the DAG and edges of the DAG encoding input/output relationships of the first list of quantum gates; determining whether control and target qubits of each CNOT gate in the subcircuit are within a termination border to confirm whether there are intermediate Hadamard gates on wires that leave and re-enter the subcircuit; performing, based on the netlist representation and the DAG representation, a phase-polynomial reduction operation on the information about the first list of quantum gates to produce a second list of quantum gates that has functional equivalence to the first list of quantum gates, the phase-polynomial reduction operation including a combining of respective rotations of at least two Rz(θ) gates of the subcircuit from the first list of quantum gates into a resulting Rz(θ) gate of the second list of quantum gates, the at least two Rz(θ) gates from the first list all being applied to a same qubit, and the resulting Rz(θ) gate of the second list being applied to the same qubit as that of the at least two Rz(θ) gates from the first list, wherein each of the Rz(θ) gates is parameterizable by a rotation angle θ that can take any value in a range between 0 and 2π, a number of quantum gates in the second list of quantum gates being smaller than a number of quantum gates in the first list of quantum gates, and the netlist representation and the DAG representation being updated concurrently whenever a reduction in the number of quantum gates in the first list of quantum gates is found as part of the phase-polynomial reduction operation; and generating a new netlist representation containing information about the second list of quantum gates to implement by a quantum computer a quantum circuit comprising the quantum gates of the second list as set out in the new netlist representation.