https://bugs.llvm.org/show_bug.cgi?id=51323
Bug ID: 51323
Summary: Missed fold for if-else chain
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedb...@nondot.org
Reporter: l...@rifkin.dev
CC: llvm-bugs@lists.llvm.org
LLVM identifier conv2 is a nop but not conv1 https://godbolt.org/z/q3Eq34EY6
int conv1(std::strong_ordering s){
if(s==std::strong_ordering::less) return -1;
if(s==std::strong_ordering::equal) return 0;
if(s==std::strong_ordering::greater) return 1;
__builtin_unreachable();
}
std::strong_ordering conv2(int i){
switch(i){
case -1: return std::strong_ordering::less;
case 0: return std::strong_ordering::equal;
case 1: return std::strong_ordering::greater;
default: __builtin_unreachable();
}
}
It's valid to optimize down to a nop here https://alive2.llvm.org/ce/z/HcSsp0.
Problem appears to be related to switch <-> if-chain conversion. If conv2 is
converted to an if-chain LLVM no longer identifies it as a nop.
I submitted a related bug report last week
https://bugs.llvm.org/show_bug.cgi?id=51285, though in this case LLVM does
correctly do a switch <-> if-chain conversion as is able to make further
optimizations because of it.
This is related to a GCC bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94566.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs