Last active
August 16, 2017 21:54
-
-
Save andrewrk/7697fef9b5a60bc7467f41197c63bae4 to your computer and use it in GitHub Desktop.
can LLVM optimize out checking if op2 of a right shift is greater than bit count of op1?
This file contains 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
define i32 @main(i32, i32) { | |
%ok = icmp ult i32 %1, 32 | |
br i1 %ok, label %ok_label, label %bad_label | |
ok_label: | |
ret i32 0 | |
bad_label: | |
%a = lshr i32 %0, %1 | |
ret i32 %a | |
} |
This file contains 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
main: # @main | |
# BB#0: | |
cmpl $31, %esi | |
ja .LBB0_2 | |
# BB#1: # %ok_label | |
xorl %eax, %eax | |
retq | |
.LBB0_2: # %bad_label | |
movl %esi, %ecx | |
shrl %cl, %edi | |
movl %edi, %eax | |
retq |
This file contains 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
define i32 @main(i32, i32) { | |
%ok = icmp ult i32 %1, 32 | |
%a = lshr i32 %0, %1 | |
%result = select i1 %ok, i32 %a, i32 0 | |
ret i32 %result | |
} |
This file contains 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
main: # @main | |
# BB#0: | |
movl %esi, %ecx | |
shrl %cl, %edi | |
xorl %eax, %eax | |
cmpl $32, %esi | |
cmovbl %edi, %eax | |
retq |
This file contains 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
define i32 @main(i32, i32) { | |
%a = lshr i32 %0, %1 | |
ret i32 %a | |
} |
This file contains 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
main: # @main | |
# BB#0: | |
movl %esi, %ecx | |
shrl %cl, %edi | |
movl %edi, %eax | |
retq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment