Skip to content

Commit

Permalink
fix #7197, backport a fix to SimplifyDemandedUseBits in LLVM
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jun 19, 2014
1 parent 4b22878 commit e2ae2f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ endif
ifeq ($(USE_SYSTEM_LLVM), 1)
LLVM_CONFIG ?= llvm-config$(EXE)
LLVM_LLC ?= llc$(EXE)
JCPPFLAGS+=-DSYSTEM_LLVM
else
LLVM_CONFIG=$(LLVMROOT)/bin/llvm-config$(EXE)
LLVM_LLC=$(LLVMROOT)/bin/llc$(EXE)
Expand Down
1 change: 1 addition & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ ifeq ($(BUILD_LLDB), 1)
endif
ifeq ($(LLVM_VER),3.3)
patch -p0 < llvm-3.3.patch
patch -p0 < instcombine-llvm-3.3.patch
ifeq ($(OS),WINNT)
ifeq ($(ARCH),x86_64)
patch -p0 < win64-int128.llvm-3.3.patch
Expand Down
12 changes: 12 additions & 0 deletions deps/instcombine-llvm-3.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff -u -r -N llvm-3.3.src/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp llvm-3.3/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
--- llvm-3.3.src/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 2013-01-02 06:36:10.000000000 -0500
+++ llvm-3.3/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 2014-06-18 23:11:49.000000000 -0400
@@ -754,7 +754,7 @@
ComputeMaskedBits(I->getOperand(0), LHSKnownZero, LHSKnownOne, Depth+1);
// If it's known zero, our sign bit is also zero.
if (LHSKnownZero.isNegative())
- KnownZero |= LHSKnownZero;
+ KnownZero.setBit(KnownZero.getBitWidth() - 1);
}
break;
case Instruction::URem: {
18 changes: 17 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3884,6 +3884,10 @@ extern "C" DLLEXPORT jl_value_t *jl_new_box(jl_value_t *v)
return box;
}

#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 3 && SYSTEM_LLVM
#define INSTCOMBINE_BUG
#endif

static void init_julia_llvm_env(Module *m)
{
MDNode* tbaa_root = mbuilder->createTBAARoot("jtbaa");
Expand Down Expand Up @@ -4269,14 +4273,20 @@ static void init_julia_llvm_env(Module *m)
FPM->add(createCFGSimplificationPass()); // Clean up disgusting code
FPM->add(createPromoteMemoryToRegisterPass());// Kill useless allocas

#ifndef INSTCOMBINE_BUG
FPM->add(createInstructionCombiningPass()); // Cleanup for scalarrepl.
#endif
FPM->add(createScalarReplAggregatesPass()); // Break up aggregate allocas
#ifndef INSTCOMBINE_BUG
FPM->add(createInstructionCombiningPass()); // Cleanup for scalarrepl.
#endif
FPM->add(createJumpThreadingPass()); // Thread jumps.
// NOTE: CFG simp passes after this point seem to hurt native codegen.
// See issue #6112. Should be re-evaluated when we switch to MCJIT.
//FPM->add(createCFGSimplificationPass()); // Merge & remove BBs
#ifndef INSTCOMBINE_BUG
FPM->add(createInstructionCombiningPass()); // Combine silly seq's
#endif

//FPM->add(createCFGSimplificationPass()); // Merge & remove BBs
FPM->add(createReassociatePass()); // Reassociate expressions
Expand All @@ -4294,7 +4304,9 @@ static void init_julia_llvm_env(Module *m)
FPM->add(createLICMPass()); // Hoist loop invariants
FPM->add(createLoopUnswitchPass()); // Unswitch loops.
// Subsequent passes not stripping metadata from terminator
FPM->add(createInstructionCombiningPass());
#ifndef INSTCOMBINE_BUG
FPM->add(createInstructionCombiningPass());
#endif
FPM->add(createIndVarSimplifyPass()); // Canonicalize indvars
FPM->add(createLoopDeletionPass()); // Delete dead loops
FPM->add(createLoopUnrollPass()); // Unroll small loops
Expand All @@ -4303,7 +4315,9 @@ static void init_julia_llvm_env(Module *m)
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 3
FPM->add(createLoopVectorizePass()); // Vectorize loops
#endif
#ifndef INSTCOMBINE_BUG
FPM->add(createInstructionCombiningPass()); // Clean up after the unroller
#endif
FPM->add(createGVNPass()); // Remove redundancies
//FPM->add(createMemCpyOptPass()); // Remove memcpy / form memset
FPM->add(createSCCPPass()); // Constant prop with SCCP
Expand All @@ -4312,7 +4326,9 @@ static void init_julia_llvm_env(Module *m)
// opened up by them.
FPM->add(createSinkingPass()); ////////////// ****
FPM->add(createInstructionSimplifierPass());///////// ****
#ifndef INSTCOMBINE_BUG
FPM->add(createInstructionCombiningPass());
#endif
FPM->add(createJumpThreadingPass()); // Thread jumps
FPM->add(createDeadStoreEliminationPass()); // Delete dead stores

Expand Down
7 changes: 7 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -877,3 +877,10 @@ A = [randn(2,2) for i = 1:2, j = 1:2]
@test issym(A.'A)
A = [complex(randn(2,2), randn(2,2)) for i = 1:2, j = 1:2]
@test ishermitian(A'A)

# issue #7197
function i7197()
S = [1 2 3; 4 5 6; 7 8 9]
ind2sub(size(S), 5)
end
@test i7197() == (2,2)

0 comments on commit e2ae2f8

Please sign in to comment.