-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Closed
Labels
llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization
Description
Test case: https://godbolt.org/z/7caGb3avf
int n1;
void func1(int a){
if(a>0&&a<10){
n1=(a+a+a+a)/(a+a);
}
}It appears that InstCombine is missing this pattern (a+a+a+a)/(a+a) => 2
clang -O3:
if.then:
%a.tr = trunc i32 %a to i8
%div.lhs.trunc = shl nuw nsw i8 %a.tr, 2
%div.rhs.trunc = shl nuw nsw i8 %a.tr, 1
%div12 = udiv i8 %div.lhs.trunc, %div.rhs.trunc
%div.zext = zext i8 %div12 to i32
store i32 %div.zext, ptr @n1, align 4
br label %if.endfunc1(int): # @func1(int)
lea eax, [rdi - 1]
cmp eax, 8
ja .LBB0_2
lea eax, [4*rdi]
add dil, dil
movzx eax, al
div dil
movzx eax, al
mov dword ptr [rip + n1], eax
.LBB0_2: # %if.end
retMetadata
Metadata
Assignees
Labels
llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization