Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 185966c

Browse files
author
Quentin Colombet
committed
[InstCombine] Revert r238452: Fold IntToPtr and PtrToInt into preceding loads.
According to git bisect, this is the root cause of a miscompile for Regex in libLLVMSupport. I am still working on reducing a test case. The actual bug may be elsewhere and this commit just exposed it. Anyway, at the moment, to reproduce, follow these steps: 1. Build clang and libLTO in release mode. 2. Create a new build directory <stage2> and cd into it. 3. Use clang and libLTO from #1 to build llvm-extract in Release mode + asserts using -O2 -flto 4. Run llvm-extract -ralias '.*bar' -S test/Other/extract-alias.ll Result: program doesn't contain global named '.*bar'! Expected result: @a0a0bar = alias void ()* @bar @a0bar = alias void ()* @bar declare void @bar() Note: In step #3, if you don't use lto or asserts, the miscompile disappears. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259674 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8e9339f commit 185966c

File tree

4 files changed

+7
-169
lines changed

4 files changed

+7
-169
lines changed

lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,17 +495,12 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
495495
}
496496

497497
// Fold away bit casts of the loaded value by loading the desired type.
498-
// We can do this for BitCastInsts as well as casts from and to pointer types,
499-
// as long as those are noops (i.e., the source or dest type have the same
500-
// bitwidth as the target's pointers).
501498
if (LI.hasOneUse())
502-
if (auto* CI = dyn_cast<CastInst>(LI.user_back())) {
503-
if (CI->isNoopCast(DL)) {
504-
LoadInst *NewLoad = combineLoadToNewType(IC, LI, CI->getDestTy());
505-
CI->replaceAllUsesWith(NewLoad);
506-
IC.eraseInstFromFunction(*CI);
507-
return &LI;
508-
}
499+
if (auto *BC = dyn_cast<BitCastInst>(LI.user_back())) {
500+
LoadInst *NewLoad = combineLoadToNewType(IC, LI, BC->getDestTy());
501+
BC->replaceAllUsesWith(NewLoad);
502+
IC.eraseInstFromFunction(*BC);
503+
return &LI;
509504
}
510505

511506
// FIXME: We should also canonicalize loads of vectors when their elements are

test/Transforms/InstCombine/load-bitcast32.ll

Lines changed: 0 additions & 79 deletions
This file was deleted.

test/Transforms/InstCombine/load-bitcast64.ll

Lines changed: 0 additions & 78 deletions
This file was deleted.

test/Transforms/InstCombine/memset_chk-1.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ entry:
7272
%yo107 = call i64 @llvm.objectsize.i64.p0i8(i8* %b, i1 false)
7373
%call50 = call i8* @__memmove_chk(i8* %b, i8* %a, i64 %add180, i64 %yo107)
7474
; CHECK: %strlen = call i64 @strlen(i8* %b)
75-
; CHECK-NEXT: %strchr2 = getelementptr i8, i8* %b, i64 %strlen
75+
; CHECK-NEXT: [[STRCHR:%[0-9a-zA-Z_-]+]] = getelementptr i8, i8* %b, i64 %strlen
7676
%call51i = call i8* @strrchr(i8* %b, i32 0)
7777
%d = load i8*, i8** %c, align 8
7878
%sub182 = ptrtoint i8* %d to i64
7979
%sub183 = ptrtoint i8* %b to i64
8080
%sub184 = sub i64 %sub182, %sub183
8181
%add52.i.i = add nsw i64 %sub184, 1
82-
; CHECK: call void @llvm.memset.p0i8.i64(i8* %strchr2
82+
; CHECK: call void @llvm.memset.p0i8.i64(i8* [[STRCHR]]
8383
%call185 = call i8* @__memset_chk(i8* %call51i, i32 0, i64 %add52.i.i, i64 -1)
8484
ret i32 4
8585
}

0 commit comments

Comments
 (0)