Created
September 21, 2025 03:46
-
-
Save raymondtay/7e9af51ebe7a7860afb9ac58f2092d67 to your computer and use it in GitHub Desktop.
The test file against the ValueTracking pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'test' | |
source_filename = "test.c" | |
target datalayout = "e-m:e-i64:64-n32:64" | |
declare void @llvm.assume(i1) | |
define i32 @demo(i32 %x, i32 %y) { | |
entry: | |
; Assume x >= 1 (=> nonzero, clears sign info) | |
%cmp = icmp sge i32 %x, 1 | |
call void @llvm.assume(i1 %cmp) | |
; pow2 = x & -x -> known power-of-two (lowbit) | |
%negx = sub i32 0, %x | |
%pow2 = and i32 %x, %negx | |
; high = shl nuw i32 1, 8 ; NUW helps known bits | |
%high = shl nuw i32 1, 8 | |
; mix = or i32 %pow2, %high | |
%mix = or i32 %pow2, %high | |
; only low 8 bits used later (lets demanded-bits fold) | |
%trunc = trunc i32 %mix to i8 | |
%zext = zext i8 %trunc to i32 | |
; FP: start from positive finite number | |
%f = fadd nnan nsz float 1.0, 2.0 ; no NaN, not negative zero | |
%g = fmul nnan nsz float %f, 0x3F800000 ; *1.0 | |
ret i32 %zext | |
} | |
define i32 @ptr_demo(i32* nonnull align 16 %p) { | |
entry: | |
; load from a nonnull, 16-aligned pointer | |
%v = load i32, i32* %p, align 16 | |
ret i32 %v | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment