[PATCH] D153511: [BasicAA] Don't short-circuit non-capturing arguments

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 01:45:55 PDT 2023


nikic created this revision.
nikic added reviewers: fhahn, aeubanks, asbirlea.
Herald added subscribers: jeroen.dobbelaere, StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a possible alternative to D153464 <https://reviews.llvm.org/D153464>. BasicAA currently assumes that an unescaped alloca cannot be read through non-nocapture arguments of a call, based on the argument that if the argument were based on the alloca, it would not be unescaped.

This currently fails in the case where the call is an ephemeral value and as such does not count as a capture. It could also happen if CaptureTracking were slightly smarter and continued following captures on call return values.


https://reviews.llvm.org/D153511

Files:
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/test/Transforms/PhaseOrdering/dse-ephemeral-value-captures.ll


Index: llvm/test/Transforms/PhaseOrdering/dse-ephemeral-value-captures.ll
===================================================================
--- llvm/test/Transforms/PhaseOrdering/dse-ephemeral-value-captures.ll
+++ llvm/test/Transforms/PhaseOrdering/dse-ephemeral-value-captures.ll
@@ -26,7 +26,13 @@
 define i32 @test() {
 ; CHECK-LABEL: define i32 @test() {
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    unreachable
+; CHECK-NEXT:    br label [[THEN_I:%.*]]
+; CHECK:       then.i:
+; CHECK-NEXT:    [[RES_I:%.*]] = call i1 @cond()
+; CHECK-NEXT:    br label [[CHECK_COND_EXIT:%.*]]
+; CHECK:       check_cond.exit:
+; CHECK-NEXT:    call void @llvm.assume(i1 [[RES_I]])
+; CHECK-NEXT:    ret i32 0
 ;
 entry:
   %a = alloca i32, align 4
Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -877,12 +877,7 @@
     unsigned OperandNo = 0;
     for (auto CI = Call->data_operands_begin(), CE = Call->data_operands_end();
          CI != CE; ++CI, ++OperandNo) {
-      // Only look at the no-capture or byval pointer arguments.  If this
-      // pointer were passed to arguments that were neither of these, then it
-      // couldn't be no-capture.
-      if (!(*CI)->getType()->isPointerTy() ||
-          (!Call->doesNotCapture(OperandNo) && OperandNo < Call->arg_size() &&
-           !Call->isByValArgument(OperandNo)))
+      if (!(*CI)->getType()->isPointerTy())
         continue;
 
       // Call doesn't access memory through this operand, so we don't care


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153511.533510.patch
Type: text/x-patch
Size: 1620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230622/36aa43ad/attachment.bin>


More information about the llvm-commits mailing list