Skip to content

Commit d53ce3d

Browse files
Merge branch 'main' into main
2 parents 2958b7b + 5a4c6f9 commit d53ce3d

File tree

8 files changed

+258
-113
lines changed

8 files changed

+258
-113
lines changed

clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,7 @@ void test_get_workgroup_size(int d, global int *out)
638638

639639
// CHECK-LABEL: @test_get_grid_size(
640640
// CHECK: {{.*}}call align 4 dereferenceable(64){{.*}} ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
641-
// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 12
642-
// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load
643-
// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 16
644-
// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load
645-
// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 20
641+
// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 %.sink
646642
// CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load
647643
void test_get_grid_size(int d, global int *out)
648644
{

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,9 @@ bool onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V);
805805
///
806806
/// If the CtxI is specified this method performs context-sensitive analysis
807807
/// and returns true if it is safe to execute the instruction immediately
808-
/// before the CtxI.
808+
/// before the CtxI. If the instruction has (transitive) operands that don't
809+
/// dominate CtxI, the analysis is performed under the assumption that these
810+
/// operands will also be speculated to a point before CxtI.
809811
///
810812
/// If the CtxI is NOT specified this method only looks at the instruction
811813
/// itself and its operands, so if this method returns true, it is safe to

llvm/lib/Analysis/Loads.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ static bool isDereferenceableAndAlignedPointer(
104104
if (CheckForNonNull &&
105105
!isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI)))
106106
return false;
107+
// When using something like !dereferenceable on a load, the
108+
// dereferenceability may only be valid on a specific control-flow path.
109+
// If the instruction doesn't dominate the context instruction, we're
110+
// asking about dereferenceability under the assumption that the
111+
// instruction has been speculated to the point of the context instruction,
112+
// in which case we don't know if the dereferenceability info still holds.
113+
// We don't bother handling allocas here, as they aren't speculatable
114+
// anyway.
115+
auto *I = dyn_cast<Instruction>(V);
116+
if (I && !isa<AllocaInst>(I))
117+
return CtxI && isValidAssumeForContext(I, CtxI, DT);
107118
return true;
108119
};
109120
if (IsKnownDeref()) {

llvm/lib/Analysis/MemDerefPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ PreservedAnalyses MemDerefPrinterPass::run(Function &F,
3030
for (auto &I : instructions(F)) {
3131
if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
3232
Value *PO = LI->getPointerOperand();
33-
if (isDereferenceablePointer(PO, LI->getType(), DL))
33+
if (isDereferenceablePointer(PO, LI->getType(), DL, LI))
3434
Deref.push_back(PO);
3535
if (isDereferenceableAndAlignedPointer(PO, LI->getType(), LI->getAlign(),
36-
DL))
36+
DL, LI))
3737
DerefAndAligned.insert(PO);
3838
}
3939
}

llvm/lib/CodeGen/MachineOperand.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,8 @@ bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C,
10471047
return false;
10481048

10491049
return isDereferenceableAndAlignedPointer(
1050-
BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL);
1050+
BasePtr, Align(1), APInt(DL.getPointerSizeInBits(), Offset + Size), DL,
1051+
dyn_cast<Instruction>(BasePtr));
10511052
}
10521053

10531054
/// getConstantPool - Return a MachinePointerInfo record that refers to the

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,13 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
11161116
*FOp, ICA.getArgTypes()[0], UI->getPointerAlignment(),
11171117
UI->getOperand(1)->getType()->getPointerAddressSpace(), CostKind);
11181118
}
1119+
case Intrinsic::vp_select: {
1120+
Intrinsic::ID IID = ICA.getID();
1121+
std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
1122+
assert(FOp.has_value());
1123+
return getCmpSelInstrCost(*FOp, ICA.getReturnType(), ICA.getArgTypes()[0],
1124+
CmpInst::BAD_ICMP_PREDICATE, CostKind);
1125+
}
11191126
}
11201127

11211128
if (ST->hasVInstructions() && RetTy->isVectorTy()) {

llvm/test/Analysis/CostModel/RISCV/rvv-select.ll

Lines changed: 225 additions & 100 deletions
Large diffs are not rendered by default.

llvm/test/Transforms/SimplifyCFG/speculate-derefable-load.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ exit:
7777
ret i64 %res
7878
}
7979

80-
; FIXME: This is a miscompile.
8180
define i64 @deref_no_hoist(i1 %c, ptr align 8 dereferenceable(8) %p1) {
8281
; CHECK-LABEL: define i64 @deref_no_hoist(
8382
; CHECK-SAME: i1 [[C:%.*]], ptr align 8 dereferenceable(8) [[P1:%.*]]) {
84-
; CHECK-NEXT: [[ENTRY:.*:]]
85-
; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P1]], align 8, !align [[META0:![0-9]+]]
83+
; CHECK-NEXT: [[ENTRY:.*]]:
84+
; CHECK-NEXT: br i1 [[C]], label %[[IF:.*]], label %[[EXIT:.*]]
85+
; CHECK: [[IF]]:
86+
; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P1]], align 8, !dereferenceable [[META0:![0-9]+]], !align [[META0]]
8687
; CHECK-NEXT: [[V:%.*]] = load i64, ptr [[P2]], align 8
87-
; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i64 [[V]], i64 0
88+
; CHECK-NEXT: br label %[[EXIT]]
89+
; CHECK: [[EXIT]]:
90+
; CHECK-NEXT: [[RES:%.*]] = phi i64 [ [[V]], %[[IF]] ], [ 0, %[[ENTRY]] ]
8891
; CHECK-NEXT: ret i64 [[RES]]
8992
;
9093
entry:

0 commit comments

Comments
 (0)