[llvm] 129af4d - [SCEVExpander][OpaquePtr] Check GEP source type when finding identical GEP
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 17 08:50:59 PST 2022
Author: Arthur Eubanks
Date: 2022-02-17T08:48:11-08:00
New Revision: 129af4daa7ce6ca8d1d649de4eba76129c199399
URL: https://github.com/llvm/llvm-project/commit/129af4daa7ce6ca8d1d649de4eba76129c199399
DIFF: https://github.com/llvm/llvm-project/commit/129af4daa7ce6ca8d1d649de4eba76129c199399.diff
LOG: [SCEVExpander][OpaquePtr] Check GEP source type when finding identical GEP
Fixes an opaque pointers miscompile.
Reviewed By: #opaque-pointers, nikic
Differential Revision: https://reviews.llvm.org/D120004
Added:
Modified:
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 007578d9ada7..754382aa0845 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -591,7 +591,9 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
if (isa<DbgInfoIntrinsic>(IP))
ScanLimit++;
if (IP->getOpcode() == Instruction::GetElementPtr &&
- IP->getOperand(0) == V && IP->getOperand(1) == Idx)
+ IP->getOperand(0) == V && IP->getOperand(1) == Idx &&
+ cast<GEPOperator>(&*IP)->getSourceElementType() ==
+ Type::getInt8Ty(Ty->getContext()))
return &*IP;
if (IP == BlockBegin) break;
}
diff --git a/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll b/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll
index c6af7014ef53..3b36930b68ba 100644
--- a/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll
+++ b/llvm/test/Transforms/IndVarSimplify/opaque-ptr.ll
@@ -8,12 +8,13 @@ define void @test(ptr %arg) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[O:%.*]] = getelementptr ptr, ptr [[ARG:%.*]], i64 16
; CHECK-NEXT: call void @c(ptr [[O]])
+; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr [[ARG]], i64 16
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IDX]], 1
; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[INC]], 16
-; CHECK-NEXT: call void @c(ptr [[O]])
+; CHECK-NEXT: call void @c(ptr [[UGLYGEP]])
; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[END:%.*]]
; CHECK: end:
; CHECK-NEXT: ret void
More information about the llvm-commits
mailing list