Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ Instruction *InstCombinerImpl::foldCmpLoadFromIndexedGlobal(
DL.getTypeAllocSize(Init->getType()->getArrayElementType());
auto MaskIdx = [&](Value *Idx) {
if (!GEP->isInBounds() && llvm::countr_zero(ElementSize) != 0) {
Value *Mask = ConstantInt::get(Idx->getType(), -1);
// EraVM local begin
Value *Mask = ConstantInt::get(Idx->getType(), -1, true);
// EraVM local end
Mask = Builder.CreateLShr(Mask, llvm::countr_zero(ElementSize));
Idx = Builder.CreateAnd(Idx, Mask);
}
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/Transforms/InstCombine/load-cmp-bug.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
; RUN: opt -passes=instcombine -S < %s | FileCheck %s

target datalayout = "E-p:256:256-i256:256:256-S32-a:256:256"

@G16 = internal constant [10 x i256] [i256 35, i256 82, i256 69, i256 81, i256 85,
i256 73, i256 82, i256 69, i256 68, i256 0]

define i1 @test_noinbounds(i256 %X) {
; CHECK-LABEL: define i1 @test_noinbounds
; CHECK-SAME: (i256 [[X:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = and i256 [[X]], 3618502788666131106986593281521497120414687020801267626233049500247285301247
; CHECK-NEXT: [[R:%.*]] = icmp eq i256 [[TMP1]], 9
; CHECK-NEXT: ret i1 [[R]]
;
%P = getelementptr [10 x i256], ptr @G16, i256 0, i256 %X
%Q = load i256, ptr %P
%R = icmp eq i256 %Q, 0
ret i1 %R
}