Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(venom): convert selection branches to branchless select #4507

Open
charles-cooper opened this issue Mar 8, 2025 · 1 comment
Open

(venom): convert selection branches to branchless select #4507

charles-cooper opened this issue Mar 8, 2025 · 1 comment
Labels

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Mar 8, 2025

for branches which just serve the purpose of selecting a variable for a phi, we should be able to convert to a branchless select. for instance, the following code

main:
    %1 = ...
    %2 = ...
    %cond = ...
    jnz %cond, @then, @else

then:
    %3 = %1
    jmp @join

else:
    %4 = %2
    jmp @join

join:
    %5 = phi @then, %3, @else, %4

could be converted to

main:
    %1 = ...
    %2 = ...
    %cond = ...
    %tmp1 = xor %1, %2
    %tmp2 = iszero %cond  ; ensure it's in (0, 1)
    %tmp3 = mul %tmp2, %tmp1
    %tmp4 = xor %tmp3, %1  ; or maybe xor %tmp3, %2? double check
    %5 = %tmp4
@charles-cooper charles-cooper changed the title convert selection branches to branchless select (venom): convert selection branches to branchless select Mar 8, 2025
@charles-cooper
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant