Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
define i32 @foo(i32 %a) nounwind readnone ssp {
entry:
%and = and i32 %a, -16
%div = sdiv i32 %and, 16
ret i32 %div
}
but this code (X & -A)/A is X >> log2(A) when A is a power of 2, so this case
should be instcombined into just "a >> 4".
We do get this at the codegen level, so something knows about it, but
instcombine should catch it earlier:
_foo: ## @foo
## BB#0: ## %entry
movl %edi, %eax
sarl $4, %eax
ret
//===---------------------------------------------------------------------===//
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
This code (from GCC PR28685):
int test(int a, int b) {
int lt = a < b;
int eq = a == b;
if (lt)
return 1;
return eq;
}
Is compiled to:
define i32 @test(i32 %a, i32 %b) nounwind readnone ssp {
entry:
%cmp = icmp slt i32 %a, %b
br i1 %cmp, label %return, label %if.end
if.end: ; preds = %entry
%cmp5 = icmp eq i32 %a, %b
%conv6 = zext i1 %cmp5 to i32
ret i32 %conv6
return: ; preds = %entry
ret i32 1
}
it could be:
define i32 @test__(i32 %a, i32 %b) nounwind readnone ssp {
entry:
%0 = icmp sle i32 %a, %b
%retval = zext i1 %0 to i32
ret i32 %retval
}
//===---------------------------------------------------------------------===//
This compare could fold to false:
define i1 @g(i32 a) nounwind readnone {
%add = shl i32 %a, 1
%mul = shl i32 %a, 1
%cmp = icmp ugt i32 %add, %mul
ret i1 %cmp
}
//===---------------------------------------------------------------------===//
This code can be seen in viterbi:
%64 = call noalias i8* @malloc(i64 %62) nounwind
...
%67 = call i64 @llvm.objectsize.i64(i8* %64, i1 false) nounwind
%68 = call i8* @__memset_chk(i8* %64, i32 0, i64 %62, i64 %67) nounwind
llvm.objectsize.i64 should be taught about malloc/calloc, allowing it to
fold to %62. This is a security win (overflows of malloc will get caught)
and also a performance win by exposing more memsets to the optimizer.
This occurs several times in viterbi.
//===---------------------------------------------------------------------===//