[PATCH] D43695: [IPSCCP] mark musttail calls overdefined (PR36485)
Fedor Indutny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 14:11:29 PST 2018
indutny created this revision.
indutny added reviewers: davide, sanjoy, bruno, dberlin, llvm-commits.
`musttail` call must be followed by a `ret` instruction with a return
value of the call as the operand. During constant propagation, the
return value maybe folded directly into `ret` instruction, breaking the
`musttail` semantics. Mark `musttail` result as overdefined to prevent
this.
Repository:
rL LLVM
https://reviews.llvm.org/D43695
Files:
lib/Transforms/Scalar/SCCP.cpp
test/Transforms/SCCP/musttail-call.ll
Index: test/Transforms/SCCP/musttail-call.ll
===================================================================
--- /dev/null
+++ test/Transforms/SCCP/musttail-call.ll
@@ -0,0 +1,27 @@
+; RUN: opt < %s -ipsccp -S | FileCheck %s
+
+declare i32 @external()
+
+define i8* @start(i8* %p, i8* %endp, i32 %match) {
+ %i0 = icmp ne i8* %p, %endp
+ br i1 %i0, label %b0_has_data, label %b1_no_data
+b0_has_data:
+ %i2 = load i8, i8* %p
+ switch i8 %i2, label %b2_switch_otherwise [ i8 32, label %b3_case_32 ]
+b1_no_data:
+ %i3 = bitcast i8* (i8*, i8*, i32)* @start to i8*
+ ret i8* %i3
+b2_switch_otherwise:
+ %i4 = musttail call i8* @start(i8* %p, i8* %endp, i32 0)
+ ret i8* %i4
+b3_case_32:
+ %i5 = musttail call i8* @invoke(i8* %p, i8* %endp, i32 0)
+ ret i8* %i5
+}
+
+define internal i8* @invoke(i8* %p, i8* %endp, i32 %match) {
+ %i1 = call i32 @external()
+ %i2 = musttail call i8* @start(i8* %p, i8* %endp, i32 0)
+ ret i8* %i2
+}
+
Index: lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- lib/Transforms/Scalar/SCCP.cpp
+++ lib/Transforms/Scalar/SCCP.cpp
@@ -1229,6 +1229,10 @@
// If so, propagate the return value of the callee into this call result.
mergeInValue(I, TFRVI->second);
}
+
+ // Replacing `musttail` instructions with constant breaks `musttail` semantics
+ if (CS.isMustTailCall())
+ return markOverdefined(I);
}
void SCCPSolver::Solve() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43695.135697.patch
Type: text/x-patch
Size: 1446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180223/56776bd5/attachment.bin>
More information about the llvm-commits
mailing list