小编Kod*_*oda的帖子

如何编写 LLVM 通道来检测 C/C++ 中的冗余条件

我想编写一个 LLVM 传递来检测 C++ 中的冗余条件模式。

int a = ... , b = ..., c = ...
//first if condition
if(a == b + 1 - c){
    ...//compoundStmt1
}
// not change the val of a, b ,c
...
//second if condition which is equivalent to first one
if(c == b - a + 1){ // redundant condition 
     ... //compoundStmt2
}

Run Code Online (Sandbox Code Playgroud)

如果我能够找到等效的条件,我可以合并compoundStmt1和CompoundStmt2。(这是我的目标!)

对于这种情况,我的想法是通过检查最后一句是否是条件分支跳转指令以及条件是ICMP或FCMP指令,找到CFG上C++中的所有条件语句,并将它们添加到后续节点中,添加条件约束的当前节点,并继续传播给后继节点。

但后来我想,对于第二个if语句,其实会加上a == b + 1 - ca != b + 1 - c,其实相当于不加。我该如何处理,判断第二次遇到的情况c …

c++ llvm llvm-ir

5
推荐指数
1
解决办法
430
查看次数

标签 统计

c++ ×1

llvm ×1

llvm-ir ×1