From e2ae2f87c2604adbc805f09fd16c30a464dc6420 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 18 Jun 2014 23:21:01 -0400 Subject: [PATCH] fix #7197, backport a fix to SimplifyDemandedUseBits in LLVM --- Make.inc | 1 + deps/Makefile | 1 + deps/instcombine-llvm-3.3.patch | 12 ++++++++++++ src/codegen.cpp | 18 +++++++++++++++++- test/arrayops.jl | 7 +++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 deps/instcombine-llvm-3.3.patch diff --git a/Make.inc b/Make.inc index c64e299e0d747..d14c93c722cf0 100644 --- a/Make.inc +++ b/Make.inc @@ -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) diff --git a/deps/Makefile b/deps/Makefile index 5d7662e062ca9..08316ceb6e107 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -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 diff --git a/deps/instcombine-llvm-3.3.patch b/deps/instcombine-llvm-3.3.patch new file mode 100644 index 0000000000000..d7f0edc21cab3 --- /dev/null +++ b/deps/instcombine-llvm-3.3.patch @@ -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: { diff --git a/src/codegen.cpp b/src/codegen.cpp index c7e3c6d66b8e9..8cbae820f0bfb 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -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"); @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/arrayops.jl b/test/arrayops.jl index bc505fa3c4a06..64078621d6f5c 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -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)