Re: [swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread Michael Gottesman via swift-dev
I posted a quick comment there + the llvm ir. It seems like something that could be a simple SimplifyInstructions transformation. Michael > On Jan 1, 2018, at 6:37 PM, David Zarzycki wrote: > > > >> On Jan 1, 2018, at 18:20, John McCall wrote: >> >>> >>>

Re: [swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread David Zarzycki via swift-dev
> On Jan 1, 2018, at 18:20, John McCall wrote: > >> >> On Jan 1, 2018, at 5:51 PM, David Zarzycki via swift-dev >> > wrote: >> >> Hi Michael, >> >> I reduced it down to a simple test case. I was wrong about this requiring

Re: [swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread John McCall via swift-dev
> On Jan 1, 2018, at 5:51 PM, David Zarzycki via swift-dev > wrote: > > Hi Michael, > > I reduced it down to a simple test case. I was wrong about this requiring two > or more dyn_casts. This actually affects any C++ code that uses the “if (auto > x = y(z))” convention.

Re: [swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread David Zarzycki via swift-dev
Hi Michael, I reduced it down to a simple test case. I was wrong about this requiring two or more dyn_casts. This actually affects any C++ code that uses the “if (auto x = y(z))” convention. What follows is the reduction (compiled with “clang++ -O3 -c” if it matters): // Uncomment the next

Re: [swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread David Zarzycki via swift-dev
I don’t have the IR handy. You can easily generate it for yourself though. Just drop the following into any file (I use swift/lib/AST/Type.cpp) and recompile swift. Decl *my_test_function(Type t) { return t->getClassOrBoundGenericClass(); } > On Jan 1, 2018, at 12:53, Michael Gottesman

Re: [swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread Michael Gottesman via swift-dev
Do you have the llvm-ir handy? > On Jan 1, 2018, at 11:30 AM, David Zarzycki via swift-dev > wrote: > > Hello, > > I noticed recently that the code gen of > CanType::getClassOrBoundGenericClass() could be better and along the way I > found a clang/LLVM bug. Where

[swift-dev] Weird dyn_cast code gen / performance problem

2018-01-01 Thread David Zarzycki via swift-dev
Hello, I noticed recently that the code gen of CanType::getClassOrBoundGenericClass() could be better and along the way I found a clang/LLVM bug. Where exactly, I do not know, although my bet is the LLVM optimizer. When more than one dyn_cast() happens in a row, LLVM/clang emits redundant and