[llvm] 383e350 - [CaptureTracking] Treat vector GEPs as captures

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 01:10:01 PST 2023


Author: Nikita Popov
Date: 2023-12-05T10:09:52+01:00
New Revision: 383e35048e16c85ab26bc46822d3ceb11fd4d3f2

URL: https://github.com/llvm/llvm-project/commit/383e35048e16c85ab26bc46822d3ceb11fd4d3f2
DIFF: https://github.com/llvm/llvm-project/commit/383e35048e16c85ab26bc46822d3ceb11fd4d3f2.diff

LOG: [CaptureTracking] Treat vector GEPs as captures

Because AA does not support vectors of pointers, we have to
treat pointers that are inserted into a vector as captures. We
mostly already do so, but missed the case where getelementptr
is used to produce a vector.

Added: 
    

Modified: 
    llvm/lib/Analysis/CaptureTracking.cpp
    llvm/test/Transforms/GVN/captured-before.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index 0d6d30923bb54..7f8f7b26f8fe5 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -361,8 +361,13 @@ UseCaptureKind llvm::DetermineUseCaptureKind(
       return UseCaptureKind::MAY_CAPTURE;
     return UseCaptureKind::NO_CAPTURE;
   }
-  case Instruction::BitCast:
   case Instruction::GetElementPtr:
+    // AA does not support pointers of vectors, so GEP vector splats need to
+    // be considered as captures.
+    if (I->getType()->isVectorTy())
+      return UseCaptureKind::MAY_CAPTURE;
+    return UseCaptureKind::PASSTHROUGH;
+  case Instruction::BitCast:
   case Instruction::PHI:
   case Instruction::Select:
   case Instruction::AddrSpaceCast:

diff  --git a/llvm/test/Transforms/GVN/captured-before.ll b/llvm/test/Transforms/GVN/captured-before.ll
index 6db151983cda7..0977f6e577b56 100644
--- a/llvm/test/Transforms/GVN/captured-before.ll
+++ b/llvm/test/Transforms/GVN/captured-before.ll
@@ -133,7 +133,6 @@ loop:
   br label %loop
 }
 
-; FIXME: This is a miscompile.
 define i32 @test_splat_gep_capture(<1 x i32> %index) {
 ; CHECK-LABEL: define i32 @test_splat_gep_capture(
 ; CHECK-SAME: <1 x i32> [[INDEX:%.*]]) {
@@ -141,7 +140,8 @@ define i32 @test_splat_gep_capture(<1 x i32> %index) {
 ; CHECK-NEXT:    store i32 123, ptr [[A]], align 4
 ; CHECK-NEXT:    [[PTRS:%.*]] = getelementptr inbounds i32, ptr [[A]], <1 x i32> [[INDEX]]
 ; CHECK-NEXT:    call void @some_call(<1 x ptr> [[PTRS]])
-; CHECK-NEXT:    ret i32 123
+; CHECK-NEXT:    [[RELOAD:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT:    ret i32 [[RELOAD]]
 ;
   %a = alloca i32
   store i32 123, ptr %a


        


More information about the llvm-commits mailing list