Why should I know this?

[TODO] undef 본문

LLVM-STUDY/TODO

[TODO] undef

die4taoam 2023. 6. 16. 15:48

1. Undef
– Explicit value in the IR
– Acts like a free-floaLng hardware register
• Takes all possible bit pakerns at the specified width
• Can take a different value every Lme it is used
– Comes from uniniLalized variables
– Further reading

• We want this opLmizaLon:
%add = add nsw i32 %a, %b 
%cmp = icmp sgt i32 %add, %a 
 => 
%cmp = icmp sgt i32 %b, 0
• But undef doesn’t let us do it:
%add = add nsw i32 %INT_MAX, %1 
%cmp = icmp sgt i32 undef, %INT_MAX 
• There’s no bit pakern we can subsLtute for
the undef that makes %cmp = true
LLVM has three kinds of UB
2. Poison
– Ephemeral effect of math instrucLons that violate
• nsw – no signed wrap for add, sub, mul, shl
• nuw – no unsigned wrap for add, sub, mul, shl
• exact – no remainder for sdiv, udiv, lshr, ashr
– Designed to support speculaLve execuLon of
operaLons that might overflow
– Poison propagates via instrucLon results
– If poison reaches a side-effecLng instrucLon, the
result is true UB
LLVM has three kinds of UB

 

3. True undefined behavior
– Triggered by
• Divide by zero
• Illegal memory accesses
– Anything can happen as a result
• Typically results in corrupted execuLon or a processor
excepLon

 

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

[TODO] llvm 공부 계획 업데이트  (0) 2023.10.18
A Validated Semantics for LLVM IR  (0) 2023.06.23
symbolic execution 이란 무엇인가?  (0) 2023.05.03
instSimplify pass 튜토리얼 중...  (0) 2023.04.12
SMT survey  (0) 2023.04.12
Comments