[llvm] r371602 - [InstCombine] Fixed handling of isOpNewLike (PR11748)
David Bolvansky via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 03:37:03 PDT 2019
Author: xbolva00
Date: Wed Sep 11 03:37:03 2019
New Revision: 371602
URL: http://llvm.org/viewvc/llvm-project?rev=371602&view=rev
Log:
[InstCombine] Fixed handling of isOpNewLike (PR11748)
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/deref-alloc-fns.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=371602&r1=371601&r2=371602&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Sep 11 03:37:03 2019
@@ -4190,13 +4190,14 @@ static void annotateAnyAllocSite(CallBas
return;
if (isMallocLikeFn(&Call, TLI) && Op0C) {
- Call.addAttribute(AttributeList::ReturnIndex,
- Attribute::getWithDereferenceableOrNullBytes(
- Call.getContext(), Op0C->getZExtValue()));
- } else if (isOpNewLikeFn(&Call, TLI) && Op0C) {
- Call.addAttribute(AttributeList::ReturnIndex,
- Attribute::getWithDereferenceableBytes(
- Call.getContext(), Op0C->getZExtValue()));
+ if (isOpNewLikeFn(&Call, TLI))
+ Call.addAttribute(AttributeList::ReturnIndex,
+ Attribute::getWithDereferenceableBytes(
+ Call.getContext(), Op0C->getZExtValue()));
+ else
+ Call.addAttribute(AttributeList::ReturnIndex,
+ Attribute::getWithDereferenceableOrNullBytes(
+ Call.getContext(), Op0C->getZExtValue()));
} else if (isReallocLikeFn(&Call, TLI) && Op1C) {
Call.addAttribute(AttributeList::ReturnIndex,
Attribute::getWithDereferenceableOrNullBytes(
Modified: llvm/trunk/test/Transforms/InstCombine/deref-alloc-fns.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/deref-alloc-fns.ll?rev=371602&r1=371601&r2=371602&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/deref-alloc-fns.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/deref-alloc-fns.ll Wed Sep 11 03:37:03 2019
@@ -5,6 +5,7 @@ declare noalias i8* @malloc(i64)
declare noalias i8* @calloc(i64, i64)
declare noalias i8* @realloc(i8* nocapture, i64)
declare noalias nonnull i8* @_Znam(i64) ; throwing version of 'new'
+declare noalias nonnull i8* @_Znwm(i64) ; throwing version of 'new'
define noalias i8* @malloc_nonconstant_size(i64 %n) {
; CHECK-LABEL: @malloc_nonconstant_size(
@@ -181,13 +182,22 @@ define noalias i8* @op_new_nonconstant_s
define noalias i8* @op_new_constant_size() {
; CHECK-LABEL: @op_new_constant_size(
-; CHECK-NEXT: [[CALL:%.*]] = tail call dereferenceable_or_null(40) i8* @_Znam(i64 40)
+; CHECK-NEXT: [[CALL:%.*]] = tail call dereferenceable(40) i8* @_Znam(i64 40)
; CHECK-NEXT: ret i8* [[CALL]]
;
%call = tail call i8* @_Znam(i64 40)
ret i8* %call
}
+define noalias i8* @op_new_constant_size2() {
+; CHECK-LABEL: @op_new_constant_size2(
+; CHECK-NEXT: [[CALL:%.*]] = tail call dereferenceable(40) i8* @_Znwm(i64 40)
+; CHECK-NEXT: ret i8* [[CALL]]
+;
+ %call = tail call i8* @_Znwm(i64 40)
+ ret i8* %call
+}
+
define noalias i8* @op_new_constant_zero_size() {
; CHECK-LABEL: @op_new_constant_zero_size(
; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @_Znam(i64 0)
More information about the llvm-commits
mailing list