Skip to content

Commit 8c06a68

Browse files
committed
C++ IR: Remove redundant check for same function
The check that an instruction is in the same function as its operands is hopefully redundant and can be removed. Just to be sure, I've added the check to a sanity query. This check turned out to cause bad performance in the alias analysis because it got inlined into `AliasAnalysis::resultEscapes` and then pulled out to a loop-invariant predicate that got a bad join order. With this check removed, the `ssa/AliasAnalysis.qll` file is orders of magnitude faster.
1 parent badb167 commit 8c06a68

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

cpp/ql/src/semmle/code/cpp/ir/internal/Instruction.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module InstructionSanity {
6666
count(instr.getOperand(tag)) > 1 and
6767
not tag instanceof UnmodeledUseOperand
6868
}
69+
70+
query predicate operandAcrossFunctions(
71+
Instruction op, Instruction operand, OperandTag tag
72+
) {
73+
operand = op.getOperand(tag) and
74+
operand.getFunctionIR() != op.getFunctionIR()
75+
}
6976
}
7077

7178
/**
@@ -302,7 +309,6 @@ class Instruction extends Construction::TInstruction {
302309
* an operand with tag `useTag`.
303310
*/
304311
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
305-
useInstruction.getFunctionIR() = funcIR and
306312
this = useInstruction.getOperand(useTag)
307313
}
308314
}

cpp/ql/src/semmle/code/cpp/ssa/internal/aliased_ssa/Instruction.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module InstructionSanity {
6666
count(instr.getOperand(tag)) > 1 and
6767
not tag instanceof UnmodeledUseOperand
6868
}
69+
70+
query predicate operandAcrossFunctions(
71+
Instruction op, Instruction operand, OperandTag tag
72+
) {
73+
operand = op.getOperand(tag) and
74+
operand.getFunctionIR() != op.getFunctionIR()
75+
}
6976
}
7077

7178
/**
@@ -302,7 +309,6 @@ class Instruction extends Construction::TInstruction {
302309
* an operand with tag `useTag`.
303310
*/
304311
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
305-
useInstruction.getFunctionIR() = funcIR and
306312
this = useInstruction.getOperand(useTag)
307313
}
308314
}

cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/Instruction.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ module InstructionSanity {
6666
count(instr.getOperand(tag)) > 1 and
6767
not tag instanceof UnmodeledUseOperand
6868
}
69+
70+
query predicate operandAcrossFunctions(
71+
Instruction op, Instruction operand, OperandTag tag
72+
) {
73+
operand = op.getOperand(tag) and
74+
operand.getFunctionIR() != op.getFunctionIR()
75+
}
6976
}
7077

7178
/**
@@ -302,7 +309,6 @@ class Instruction extends Construction::TInstruction {
302309
* an operand with tag `useTag`.
303310
*/
304311
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
305-
useInstruction.getFunctionIR() = funcIR and
306312
this = useInstruction.getOperand(useTag)
307313
}
308314
}

0 commit comments

Comments
 (0)