Skip to content

Commit be88b58

Browse files
committed
[InstCombine] Call simplifyLoadInst()
InstCombine is supposed to be a superset of InstSimplify, but failed to invoke load simplification. Unfortunately, this causes a minor compile-time regression, which will be mitigated in a future commit.
1 parent 9196908 commit be88b58

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

llvm/include/llvm/Analysis/InstructionSimplify.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ Value *simplifyConstrainedFPCall(CallBase *Call, const SimplifyQuery &Q);
318318
/// If not, this returns null.
319319
Value *simplifyFreezeInst(Value *Op, const SimplifyQuery &Q);
320320

321+
/// Given a load instruction and its pointer operand, fold the result or return
322+
/// null.
323+
Value *simplifyLoadInst(LoadInst *LI, Value *PtrOp, const SimplifyQuery &Q);
324+
321325
/// See if we can compute a simplified version of this instruction. If not,
322326
/// return null.
323327
Value *simplifyInstruction(Instruction *I, const SimplifyQuery &Q,

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6590,8 +6590,8 @@ Value *llvm::simplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
65906590
return ::simplifyFreezeInst(Op0, Q);
65916591
}
65926592

6593-
static Value *simplifyLoadInst(LoadInst *LI, Value *PtrOp,
6594-
const SimplifyQuery &Q) {
6593+
Value *llvm::simplifyLoadInst(LoadInst *LI, Value *PtrOp,
6594+
const SimplifyQuery &Q) {
65956595
if (LI->isVolatile())
65966596
return nullptr;
65976597

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op) {
10241024

10251025
Instruction *InstCombinerImpl::visitLoadInst(LoadInst &LI) {
10261026
Value *Op = LI.getOperand(0);
1027+
if (Value *Res = simplifyLoadInst(&LI, Op, SQ.getWithInstruction(&LI)))
1028+
return replaceInstUsesWith(LI, Res);
10271029

10281030
// Try to canonicalize the loaded type.
10291031
if (Instruction *Res = combineLoadToOperationType(*this, LI))

llvm/test/Transforms/InstCombine/load.ll

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ define <2 x i64> @test24(ptr %P) {
395395

396396
define i16 @load_from_zero_with_dynamic_offset(i64 %idx) {
397397
; CHECK-LABEL: @load_from_zero_with_dynamic_offset(
398-
; CHECK-NEXT: [[GEP:%.*]] = getelementptr i16, ptr @GLOBAL, i64 [[IDX:%.*]]
399-
; CHECK-NEXT: [[V:%.*]] = load i16, ptr [[GEP]], align 2
400-
; CHECK-NEXT: ret i16 [[V]]
398+
; CHECK-NEXT: ret i16 0
401399
;
402400
%gep = getelementptr i16, ptr @GLOBAL, i64 %idx
403401
%v = load i16, ptr %gep
@@ -408,10 +406,7 @@ declare ptr @llvm.strip.invariant.group.p0(ptr %p)
408406

409407
define i32 @load_via_strip_invariant_group() {
410408
; CHECK-LABEL: @load_via_strip_invariant_group(
411-
; CHECK-NEXT: [[A:%.*]] = call ptr @llvm.strip.invariant.group.p0(ptr nonnull @Y)
412-
; CHECK-NEXT: [[B:%.*]] = getelementptr i8, ptr [[A]], i64 8
413-
; CHECK-NEXT: [[D:%.*]] = load i32, ptr [[B]], align 4
414-
; CHECK-NEXT: ret i32 [[D]]
409+
; CHECK-NEXT: ret i32 37
415410
;
416411
%a = call ptr @llvm.strip.invariant.group.p0(ptr @Y)
417412
%b = getelementptr i8, ptr %a, i64 8

llvm/test/Transforms/InstCombine/memcpy-from-global.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ entry:
303303
define float @test11(i64 %i) {
304304
; CHECK-LABEL: @test11(
305305
; CHECK-NEXT: entry:
306-
; CHECK-NEXT: [[G:%.*]] = getelementptr [4 x float], ptr addrspace(1) @I, i64 0, i64 [[I:%.*]]
307-
; CHECK-NEXT: [[R:%.*]] = load float, ptr addrspace(1) [[G]], align 4
308-
; CHECK-NEXT: ret float [[R]]
306+
; CHECK-NEXT: ret float 0.000000e+00
309307
;
310308

311309
entry:

0 commit comments

Comments
 (0)