This is an archive of the discontinued LLVM Phabricator instance.

[BuildLibCalls] emitPutChar should infer its function attributes
ClosedPublic

Authored by craig.topper on Mar 17 2017, 12:22 PM.

Details

Summary

When InstCombine calls into SimplifyLibCalls and it createa putChar calls, we don't infer the attributes. And since SimplifyLibCalls doesn't use InstCombine's IRBuilder the calls doesn't end up in the worklist on this iteration of InstCombine. So it gets picked up on the next iteration where it causes an IR change. This of course causes InstCombine to run another iteration.

So this patch just gets the attributes right the first time. We already did this for puts and some other libcalls.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Mar 17 2017, 12:22 PM
spatel edited edge metadata.Mar 17 2017, 1:54 PM

Can we do better than repeating this in every emit* function? Is there ever a case where we don't want to infer the attrs?

fputc and fputs check the type of one of the arguments before calling inferLibFuncAttributes. So its not always unconditional.

spatel accepted this revision.Mar 17 2017, 4:07 PM

fputc and fputs check the type of one of the arguments before calling inferLibFuncAttributes. So its not always unconditional.

In that case, LGTM.

This revision is now accepted and ready to land.Mar 17 2017, 4:07 PM
This revision was automatically updated to reflect the committed changes.
davide edited edge metadata.Mar 18 2017, 5:57 PM

Can you add a testcase?

I'm not sure how to do that. We eventually inferred the attributes. It just took a second trip through the InstCombine worklist.

You could use a debug counter to limit instcombine to one pass over the function; see http://llvm.org/docs/ProgrammersManual.html#adding-debug-counters-to-aid-in-debugging-your-code . Probably worth doing if you're planning to write more similar fixes.