Skip to content

Commit 7e1fa09

Browse files
authored
[SimplifyCFG] Bail out on vector GEPs in passingValueIsAlwaysUndefined (#142526)
Closes #142522.
1 parent dc513fa commit 7e1fa09

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8108,6 +8108,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
81088108

81098109
/// Check if passing a value to an instruction will cause undefined behavior.
81108110
static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValueMayBeModified) {
8111+
assert(V->getType() == I->getType() && "Mismatched types");
81118112
Constant *C = dyn_cast<Constant>(V);
81128113
if (!C)
81138114
return false;
@@ -8165,6 +8166,10 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
81658166
// Look through GEPs. A load from a GEP derived from NULL is still undefined
81668167
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(User))
81678168
if (GEP->getPointerOperand() == I) {
8169+
// The type of GEP may differ from the type of base pointer.
8170+
// Bail out on vector GEPs, as they are not handled by other checks.
8171+
if (GEP->getType()->isVectorTy())
8172+
return false;
81688173
// The current base address is null, there are four cases to consider:
81698174
// getelementptr (TY, null, 0) -> null
81708175
// getelementptr (TY, null, not zero) -> may be modified

llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ declare ptr @fn_nonnull_arg(ptr nonnull %p)
244244
declare ptr @fn_noundef_arg(ptr noundef %p)
245245
declare ptr @fn_ptr_arg(ptr)
246246
declare ptr @fn_ptr_arg_nounwind_willreturn(ptr) nounwind willreturn
247+
declare void @fn_arg_vec(<2 x ptr>)
247248

248249
define void @test9(i1 %X, ptr %Y) {
249250
; CHECK-LABEL: @test9(
@@ -917,6 +918,25 @@ bb5: ; preds = %bb3, %bb
917918
ret i32 %i7
918919
}
919920

921+
define void @test9_gep_splat(i1 %X, ptr %Y) {
922+
; CHECK-LABEL: @test9_gep_splat(
923+
; CHECK-NEXT: entry:
924+
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y:%.*]]
925+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[SPEC_SELECT]], <2 x i64> zeroinitializer
926+
; CHECK-NEXT: call void @fn_arg_vec(<2 x ptr> [[GEP]])
927+
; CHECK-NEXT: ret void
928+
;
929+
entry:
930+
br i1 %X, label %if, label %else
931+
if:
932+
br label %else
933+
else:
934+
%phi = phi ptr [ %Y, %entry ], [ null, %if ]
935+
%gep = getelementptr i8, ptr %phi, <2 x i64> zeroinitializer
936+
call void @fn_arg_vec(<2 x ptr> %gep)
937+
ret void
938+
}
939+
920940
declare void @side.effect()
921941
declare i8 @get.i8()
922942

0 commit comments

Comments
 (0)