[PATCH] D98925: [BasicAA] Ignore @llvm.annotation when computing ModRefInfo.
Clement Courbet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 19 00:39:36 PDT 2021
courbet created this revision.
Herald added a subscriber: hiraditya.
courbet requested review of this revision.
Herald added a project: LLVM.
@llvm.annotation is supposed to be ignored by code generation and
optimization:
https://llvm.org/docs/LangRef.html#llvm-annotation-intrinsic
However BasicAA considers that it may write to memory, so loads cannot
be moved across annotations.
BasicAA already ignores `llvm.assume` for this purpose. This change adds
`llvm.annotation`, `llvm.var.annotation` and `llvm.ptr.annotation`.
Fixes PR49638.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98925
Files:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
Index: llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/annotation-intrinsic.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -instcombine %s -S -o - | FileCheck %s
+
+; This tests that llvm.annotation does not prevent load combining.
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+declare i32 @llvm.annotation.i32(i32, i8*, i8*, i32) #1
+
+define dso_local i32 @annotated(i32* %c) local_unnamed_addr #0 {
+; CHECK-LABEL: @annotated(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[C:%.*]], align 4
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.annotation.i32(i32 [[TMP0]], i8* undef, i8* undef, i32 undef)
+; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
+; CHECK-NEXT: ret i32 [[ADD]]
+;
+entry:
+ %0 = load i32, i32* %c, align 4
+ %1 = call i32 @llvm.annotation.i32(i32 %0, i8* undef, i8* undef, i32 undef)
+ %2 = load i32, i32* %c, align 4
+ %add = add nsw i32 %1, %2
+ ret i32 %add
+}
+
+attributes #0 = { nofree nounwind uwtable willreturn mustprogress }
Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -937,6 +937,13 @@
// particular memory location.
if (isIntrinsicCall(Call, Intrinsic::assume))
return ModRefInfo::NoModRef;
+ // The same applies to annotations.
+ if (isIntrinsicCall(Call, Intrinsic::annotation))
+ return ModRefInfo::NoModRef;
+ if (isIntrinsicCall(Call, Intrinsic::var_annotation))
+ return ModRefInfo::NoModRef;
+ if (isIntrinsicCall(Call, Intrinsic::ptr_annotation))
+ return ModRefInfo::NoModRef;
// Like assumes, guard intrinsics are also marked as arbitrarily writing so
// that proper control dependencies are maintained but they never mods any
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98925.331783.patch
Type: text/x-patch
Size: 2101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210319/1e51411c/attachment.bin>
More information about the llvm-commits
mailing list