Skip to content

Commit

Permalink
Simplify test for sret attribute in instcombine
Browse files Browse the repository at this point in the history
This change is correct because the verifier requires that at most one
argument be marked 'sret'.

NFC, removes a use of AttributeList slot APIs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300784 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rnk committed Apr 19, 2017
1 parent 6b92d16 commit e7cb393
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
18 changes: 6 additions & 12 deletions lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4068,21 +4068,15 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
}

if (FT->getNumParams() < NumActualArgs && FT->isVarArg() &&
!CallerPAL.isEmpty())
!CallerPAL.isEmpty()) {
// In this case we have more arguments than the new function type, but we
// won't be dropping them. Check that these extra arguments have attributes
// that are compatible with being a vararg call argument.
for (unsigned i = CallerPAL.getNumSlots(); i; --i) {
unsigned Index = CallerPAL.getSlotIndex(i - 1);
if (Index <= FT->getNumParams())
break;

// Check if it has an attribute that's incompatible with varargs.
AttributeList PAttrs = CallerPAL.getSlotAttributes(i - 1);
if (PAttrs.hasAttribute(Index, Attribute::StructRet))
return false;
}

unsigned SRetIdx;
if (CallerPAL.hasAttrSomewhere(Attribute::StructRet, &SRetIdx) &&
SRetIdx > FT->getNumParams())
return false;
}

// Okay, we decided that this is a safe thing to do: go ahead and start
// inserting cast instructions as necessary.
Expand Down
15 changes: 0 additions & 15 deletions test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll

This file was deleted.

29 changes: 29 additions & 0 deletions test/Transforms/InstCombine/call-cast-attrs.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: opt < %s -instcombine -S | FileCheck %s

define signext i32 @b(i32* inreg %x) {
ret i32 0
}

define void @c(...) {
ret void
}

declare void @useit(i32)

define void @d(i32 %x, ...) {
call void @useit(i32 %x)
ret void
}

define void @g(i32* %y) {
call i32 bitcast (i32 (i32*)* @b to i32 (i32)*)(i32 zeroext 0)
call void bitcast (void (...)* @c to void (i32*)*)(i32* %y)
call void bitcast (void (...)* @c to void (i32*)*)(i32* sret %y)
call void bitcast (void (i32, ...)* @d to void (i32, i32*)*)(i32 0, i32* sret %y)
ret void
}
; CHECK-LABEL: define void @g(i32* %y)
; CHECK: call i32 bitcast (i32 (i32*)* @b to i32 (i32)*)(i32 zeroext 0)
; CHECK: call void (...) @c(i32* %y)
; CHECK: call void bitcast (void (...)* @c to void (i32*)*)(i32* sret %y)
; CHECK: call void bitcast (void (i32, ...)* @d to void (i32, i32*)*)(i32 0, i32* sret %y)

0 comments on commit e7cb393

Please sign in to comment.