]> granicus.if.org Git - llvm/commitdiff
[BuildLibCalls] emitPutChar should infer function attributes for putchar
authorCraig Topper <craig.topper@gmail.com>
Fri, 17 Mar 2017 23:48:02 +0000 (23:48 +0000)
committerCraig Topper <craig.topper@gmail.com>
Fri, 17 Mar 2017 23:48:02 +0000 (23:48 +0000)
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.

Differential Revision: https://reviews.llvm.org/D31094

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298171 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/BuildLibCalls.cpp

index 4f6bfcfe5245e2e7adb40ab6bc5043b138477339..240fb70f6b552887c10393b8f32ac01995754792 100644 (file)
@@ -920,6 +920,7 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B,
   Module *M = B.GetInsertBlock()->getModule();
   Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
                                           B.getInt32Ty(), nullptr);
+  inferLibFuncAttributes(*M->getFunction("putchar"), *TLI);
   CallInst *CI = B.CreateCall(PutChar,
                               B.CreateIntCast(Char,
                               B.getInt32Ty(),