Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8109,6 +8109,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {

/// Check if passing a value to an instruction will cause undefined behavior.
static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValueMayBeModified) {
assert(V->getType() == I->getType() && "Mismatched types");
Constant *C = dyn_cast<Constant>(V);
if (!C)
return false;
Expand Down Expand Up @@ -8177,6 +8178,10 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
NullPointerIsDefined(GEP->getFunction(),
GEP->getPointerAddressSpace())))
PtrValueMayBeModified = true;
// The type of GEP may differ from the type of base pointer.
if (V->getType() != GEP->getType())
V = ConstantVector::getSplat(
cast<VectorType>(GEP->getType())->getElementCount(), C);
return passingValueIsAlwaysUndefined(V, GEP, PtrValueMayBeModified);
}

Expand Down
20 changes: 20 additions & 0 deletions llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ declare ptr @fn_nonnull_arg(ptr nonnull %p)
declare ptr @fn_noundef_arg(ptr noundef %p)
declare ptr @fn_ptr_arg(ptr)
declare ptr @fn_ptr_arg_nounwind_willreturn(ptr) nounwind willreturn
declare void @fn_arg_vec(<2 x ptr>)

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

define void @test9_gep_splat(i1 %X, ptr %Y) {
; CHECK-LABEL: @test9_gep_splat(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y:%.*]]
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[SPEC_SELECT]], <2 x i64> zeroinitializer
; CHECK-NEXT: call void @fn_arg_vec(<2 x ptr> [[GEP]])
; CHECK-NEXT: ret void
;
entry:
br i1 %X, label %if, label %else
if:
br label %else
else:
%phi = phi ptr [ %Y, %entry ], [ null, %if ]
%gep = getelementptr i8, ptr %phi, <2 x i64> zeroinitializer
call void @fn_arg_vec(<2 x ptr> %gep)
ret void
}

declare void @side.effect()
declare i8 @get.i8()

Expand Down
Loading