-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed
Labels
llvm:analysisIncludes value tracking, cost tables and constant foldingIncludes value tracking, cost tables and constant foldingllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization
Description
Alive2 proof: https://alive2.llvm.org/ce/z/ERjNs4
Motivating example
define i32 @src(i32 %x) {
%add = add nsw i32 %x, 16
%cmp = icmp sgt i32 %x, 1008
%s = select i1 %cmp, i32 %add, i32 1024
ret i32 %s
}can be folded to:
define i32 @tgt(i32 %x) {
%smax = call i32 @llvm.smax.i32(i32 %x, i32 1008)
%add = add nuw nsw i32 %smax, 16
ret i32 %add
}LLVM does well when C1 or C2 is not constant, but when both are constants, LLVM missed it. Though this example doesn't show better codegen, I think it's a better canonicalization.
Real-world motivation
This snippet of IR is derived from protobuf/generated_message_tctable_lite.cc after O3 pipeline (original IR is from llvm-opt-benchmark).
Original IR is too big to attach here, email me to get it please.
Let me know if you can confirm that it's an optimization opportunity, thanks.
dtcxzyw
Metadata
Metadata
Assignees
Labels
llvm:analysisIncludes value tracking, cost tables and constant foldingIncludes value tracking, cost tables and constant foldingllvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passesCovers the InstCombine, InstSimplify and AggressiveInstCombine passesmissed-optimization