[PATCH] D67231: [Attributor][Fix] Use right type to replace expressions
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 10:13:09 PDT 2019
jdoerfert created this revision.
jdoerfert added reviewers: uenoku, sstefan1.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.
This should be obsolete once the functionality in D66967 <https://reviews.llvm.org/D66967> is integrated.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67231
Files:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/FunctionAttrs/arg_returned.ll
Index: llvm/test/Transforms/FunctionAttrs/arg_returned.ll
===================================================================
--- llvm/test/Transforms/FunctionAttrs/arg_returned.ll
+++ llvm/test/Transforms/FunctionAttrs/arg_returned.ll
@@ -827,6 +827,17 @@
ret i32 %add3
}
+ at G = external global i8
+define i32* @ret_const() {
+ %bc = bitcast i8* @G to i32*
+ ret i32* %bc
+}
+define i32* @use_const() {
+ %c = call i32* @ret_const()
+ ; CHECK: ret i32* bitcast (i8* @G to i32*)
+ ret i32* %c
+}
+
attributes #0 = { noinline nounwind uwtable }
; BOTH-NOT: attributes #
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -874,12 +874,17 @@
if (Function *F = dyn_cast<Function>(&AnchorValue)) {
for (const Use &U : F->uses())
if (CallBase *CB = dyn_cast<CallBase>(U.getUser()))
- if (CB->isCallee(&U))
- Changed = ReplaceCallSiteUsersWith(*CB, *RVC) | Changed;
+ if (CB->isCallee(&U)) {
+ Constant *RVCCast =
+ ConstantExpr::getTruncOrBitCast(RVC, CB->getType());
+ Changed = ReplaceCallSiteUsersWith(*CB, *RVCCast) | Changed;
+ }
} else {
assert(isa<CallBase>(AnchorValue) &&
"Expcected a function or call base anchor!");
- Changed = ReplaceCallSiteUsersWith(cast<CallBase>(AnchorValue), *RVC);
+ Constant *RVCCast =
+ ConstantExpr::getTruncOrBitCast(RVC, AnchorValue.getType());
+ Changed = ReplaceCallSiteUsersWith(cast<CallBase>(AnchorValue), *RVCCast);
}
if (Changed == ChangeStatus::CHANGED)
STATS_DECLTRACK(UniqueConstantReturnValue, FunctionReturn,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67231.218943.patch
Type: text/x-patch
Size: 1784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190905/66950dc7/attachment.bin>
More information about the llvm-commits
mailing list