Why should I know this?

instSimplify pass 튜토리얼 중... 본문

LLVM-STUDY/TODO

instSimplify pass 튜토리얼 중...

die4taoam 2023. 4. 12. 22:23

Simplify 테스트 케이스 중에는 다음과 같은 항목이 있습니다.
아무도 관심갖지 않는 TODO 입니다 ㅠ_ㅠ

 

; TODO: simplify this to %a
define i1 @test8(i1 %a) {
; CHECK-LABEL: @test8(
; CHECK-NEXT:    [[C:%.*]] = add i1 [[A:%.*]], true
; CHECK-NEXT:    [[RES:%.*]] = xor i1 [[C]], true
; CHECK-NEXT:    ret i1 [[RES]]
;
  %c = add i1 %a, true
  %res = xor i1 %c, true
  ret i1 %res
}
; TODO: simplify this to %a
define i1 @test10(i1 %a) {
; CHECK-LABEL: @test10(
; CHECK-NEXT:    [[C:%.*]] = sub i1 [[A:%.*]], true
; CHECK-NEXT:    [[RES:%.*]] = xor i1 [[C]], true
; CHECK-NEXT:    ret i1 [[RES]]
;
  %c = sub i1 %a, true
  %res = xor i1 %c, true
  ret i1 %res
}

 

코드만 분석하긴 지루해서 이런게 보일때마다 시도해보려고 합니다.

다음은 시도한 로그입니다.

 

[simplify-study]TestBody:750    test10                              
[simplify-study]runImpl:692     Instruction :   %c = sub i1 %a, true  
[simplify-study]runImpl:692     Instruction :   %res = xor i1 %c, true                                                                         
[simplify-study]_simplifyXorInst:283    Enter simplifyXorInst : Op0 :   %c = sub i1 %a, true
Op1 : i1 true                                                                                                                                  
[simplify-study]_simplifyLogicOfAddSub:65       _simplifyLogicOfAddSub opcode : xor
[simplify-study]_simplifyLogicOfAddSub:66       OP0 :   %c = sub i1 %a, true
[simplify-study]_simplifyLogicOfAddSub:67       OP1 : i1 true
[simplify-study]_simplifyLogicOfAddSub:90       PASS!                                                                                          
[simplify-study]_simplifyXorInst:283    Enter simplifyXorInst : Op0 :   <badref> = xor i1 %a, true
Op1 : i1 true                                                                                                                                  
[simplify-study]_simplifyLogicOfAddSub:65       _simplifyLogicOfAddSub opcode : xor
[simplify-study]_simplifyLogicOfAddSub:66       OP0 :   <badref> = xor i1 %a, true
[simplify-study]_simplifyLogicOfAddSub:67       OP1 : i1 true
[simplify-study]_simplifyLogicOfAddSub:90       PASS!                                                                                          
[simplify-study]simplifyAssociativeBinOp:176    enter simplifyAssociativeBinOp : Op : xor
[simplify-study]simplifyAssociativeBinOp:177    LHS :   <badref> = xor i1 %a, true
[simplify-study]simplifyAssociativeBinOp:178    RHS : i1 true
[simplify-study]simplifyAssociativeBinOp:192    check : i1 %a
i1 true
i1 true                                                                                                                                        
[simplify-study]_simplifyXorInst:283    Enter simplifyXorInst : Op0 : i1 true
Op1 : i1 true                                                                                                                                  
[simplify-study]_simplifyXorInst:285    foldOrCommuteConstant : i1 false         
[simplify-study]simplifyAssociativeBinOp:195    (B op C) simplifyBinOp : i1 false
[simplify-study]_simplifyXorInst:283    Enter simplifyXorInst : Op0 : i1 %a
Op1 : i1 false                                                         
[simplify-study]_simplifyXorInst:303    match(Op1, m_Zero() : i1 false                                                                         
[simplify-study]simplifyAssociativeBinOp:204    (A op V) simplifyBinOp : i1 %a
[simplify-study]_simplifyXorInst:378    simplifyAssociativeBinOp : i1 %a
[simplify-study]_simplifyXorInst:368    simplifyXorInst : i1 %a                                                                                
[simplify-study]simplifyInstructionWithOperands:666     simplify success ; i1 %a
[simplify-study]runImpl:705     has Simplified : i1 %a   
[simplify-study]runImpl:692     Instruction :   ret i1 %a
[simplify-study]runImpl:692     Instruction :   ret i1 %a         
[simplify-study]runImpl:729     [RESULT] Instruction :   ret i1 %a

 

결과는 맞는데 이게 최선인지 고민 좀 해봐야겠습니다. ^_^;;

 

'LLVM-STUDY > TODO' 카테고리의 다른 글

[TODO] undef  (0) 2023.06.16
symbolic execution 이란 무엇인가?  (0) 2023.05.03
SMT survey  (0) 2023.04.12
LLVM Obfucation example - Control Flow Flattening with ChatGPT  (0) 2023.03.19
LLVM Optimization study - simplify with ChatGPT  (0) 2023.03.19
Comments