Skip to content

Commit a9f51cb

Browse files
committed
[SimplifyCFG] Handle vector GEP in passingValueIsAlwaysUndefined
1 parent 6f64a60 commit a9f51cb

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
@@ -8109,6 +8109,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
81098109

81108110
/// Check if passing a value to an instruction will cause undefined behavior.
81118111
static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValueMayBeModified) {
8112+
assert(V->getType() == I->getType() && "Mismatched types");
81128113
Constant *C = dyn_cast<Constant>(V);
81138114
if (!C)
81148115
return false;
@@ -8177,6 +8178,10 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
81778178
NullPointerIsDefined(GEP->getFunction(),
81788179
GEP->getPointerAddressSpace())))
81798180
PtrValueMayBeModified = true;
8181+
// The type of GEP may differ from the type of base pointer.
8182+
if (V->getType() != GEP->getType())
8183+
V = ConstantVector::getSplat(
8184+
cast<VectorType>(GEP->getType())->getElementCount(), C);
81808185
return passingValueIsAlwaysUndefined(V, GEP, PtrValueMayBeModified);
81818186
}
81828187

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)