[PATCH] D119652: [OpaquePtr][ValueTracking] Check GEP source element type in isPointerOffset()

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 12 17:42:19 PST 2022


aeubanks created this revision.
Herald added a subscriber: hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fixes a MemCpyOpt miscompile with opaque pointers.
This function can be further cleaned up, but let's just fix the miscompile first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119652

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Transforms/MemCpyOpt/opaque-ptr.ll


Index: llvm/test/Transforms/MemCpyOpt/opaque-ptr.ll
===================================================================
--- llvm/test/Transforms/MemCpyOpt/opaque-ptr.ll
+++ llvm/test/Transforms/MemCpyOpt/opaque-ptr.ll
@@ -22,6 +22,7 @@
 define void @test_non_const_gep(ptr %src, i64 %i) {
 ; CHECK-LABEL: @test_non_const_gep(
 ; CHECK-NEXT:    [[PB:%.*]] = getelementptr [[B:%.*]], ptr [[SRC:%.*]], i64 0, i32 1
+; CHECK-NEXT:    store i64 0, ptr [[PB]], align 4
 ; CHECK-NEXT:    [[PA:%.*]] = getelementptr [[A:%.*]], ptr [[SRC]], i64 0, i32 1
 ; CHECK-NEXT:    [[PA2:%.*]] = getelementptr [[A]], ptr [[SRC]], i64 0, i32 2
 ; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr align 4 [[PA]], i8 0, i64 16, i1 false)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -7136,7 +7136,8 @@
   // potentially variable) indices.  After that they handle some constant
   // offset, which determines their offset from each other.  At this point, we
   // handle no other case.
-  if (!GEP1 || !GEP2 || GEP1->getOperand(0) != GEP2->getOperand(0))
+  if (!GEP1 || !GEP2 || GEP1->getOperand(0) != GEP2->getOperand(0) ||
+      GEP1->getSourceElementType() != GEP2->getSourceElementType())
     return None;
 
   // Skip any common indices and track the GEP types.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119652.408224.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220213/b5118d9a/attachment.bin>


More information about the llvm-commits mailing list