From: Torok Edwin Date: Tue, 20 Oct 2009 15:42:00 +0000 (+0000) Subject: Fix PR5258, jump-threading creating invalid PHIs. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=f993327e71d826dcb852929a78881569ef83374d Fix PR5258, jump-threading creating invalid PHIs. When an incoming value for a PHI is updated, we must also updated all other incoming values for the same BB to match, otherwise we create invalid PHIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84638 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SSAUpdater.cpp b/lib/Transforms/Utils/SSAUpdater.cpp index ee2f37b26cc..ed9c0ee6c70 100644 --- a/lib/Transforms/Utils/SSAUpdater.cpp +++ b/lib/Transforms/Utils/SSAUpdater.cpp @@ -178,10 +178,18 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) { void SSAUpdater::RewriteUse(Use &U) { Instruction *User = cast(U.getUser()); BasicBlock *UseBB = User->getParent(); - if (PHINode *UserPN = dyn_cast(User)) + PHINode *UserPN = dyn_cast(User); + if (UserPN) UseBB = UserPN->getIncomingBlock(U); - U.set(GetValueInMiddleOfBlock(UseBB)); + Value *V = GetValueInMiddleOfBlock(UseBB); + U.set(V); + if (UserPN) { + // Incoming value from the same BB must be consistent + for (unsigned i=0;igetNumIncomingValues();i++) + if (UserPN->getIncomingBlock(i) == UseBB) + UserPN->setIncomingValue(i, V); + } } diff --git a/test/Transforms/JumpThreading/2009-10-20-jumpthreading-phi.ll b/test/Transforms/JumpThreading/2009-10-20-jumpthreading-phi.ll new file mode 100644 index 00000000000..b5440c24a42 --- /dev/null +++ b/test/Transforms/JumpThreading/2009-10-20-jumpthreading-phi.ll @@ -0,0 +1,348 @@ +; RUN: opt -jump-threading -verify %s -disable-output +; PR5258 +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + +%0 = type { i64, [12 x i32] } +%1 = type { %2 } +%2 = type { i32, i32, i32, i32, i32, i32, %3 } +%3 = type { %3*, %3* } +%4 = type { i32 } +%5 = type { %6*, %84, %87, %89, %92, %95, %69, %79*, %102*, %69, %69, %69 } +%6 = type { %7* } +%7 = type { %8, %10, %28, %34, %38, %40, %40, %40, %40, %40, %40, %40, %21*, %21*, %45, %46, %45, %45, %15, %15, %15, %15, %15, %15, %15, %15, %49, %49, %49, %49, %49, %9, %9, %51, %51, %51, %51, %51, %51, %53, %56 } +%8 = type { %9, i32, i32 } +%9 = type { i8* } +%10 = type { i32, %11*, i32, i32 } +%11 = type { %12, %21* } +%12 = type { %13, %15* } +%13 = type { i32, %14 } +%14 = type { i64 } +%15 = type { %16, i8, [3 x i8], i32, %6*, %15*, %17, i32, %20* } +%16 = type { i32 (...)** } +%17 = type { %18 } +%18 = type { %19 } +%19 = type { %16**, %16**, %16** } +%20 = type { %15*, %16* } +%21 = type { %22, %13 } +%22 = type { %23 } +%23 = type { %24, %26*, i32 } +%24 = type { i32 (...)**, i8, i8, i8, i16, %25, %26*, %27* } +%25 = type { %15* } +%26 = type { %24*, %26*, %14 } +%27 = type { %4, %24* } +%28 = type { i32, %29*, i32, i32 } +%29 = type { %30, %33* } +%30 = type { %31 } +%31 = type { %32*, %14, i16, i16 } +%32 = type { i16, i16, i32, i32 } +%33 = type { %22, %31 } +%34 = type { %35, %37 } +%35 = type { %36*, i32, i32, i32, i32 } +%36 = type { i32, %4* } +%37 = type <{ i8 }> +%38 = type { %39 } +%39 = type { i32 (...)**, i8**, i32, i32 } +%40 = type { %16, %41, %41, %41, %45 } +%41 = type { %42 } +%42 = type { %43 } +%43 = type { %37, %44, i64 } +%44 = type { i32, %44*, %44*, %44* } +%45 = type { %9, i32, i8 } +%46 = type { %47, %24*, i8* } +%47 = type { %48, [8 x i8*] } +%48 = type { i8**, i32, i32, i32, [1 x i8*] } +%49 = type { %50 } +%50 = type { %15 } +%51 = type { %52, %41 } +%52 = type { %41 } +%53 = type { i32, %54*, i32, i32 } +%54 = type { %24*, %55* } +%55 = type { %14, %55*, %24* } +%56 = type { %57, %34 } +%57 = type { i32, %58*, i32, i32 } +%58 = type <{ %59*, [8 x i8], %83 }> +%59 = type { %23, %60, %62* } +%60 = type { %61, %59* } +%61 = type { %59* } +%62 = type { %24, %63, %65, %67* } +%63 = type { %64, %62* } +%64 = type { %62* } +%65 = type { %66, %59* } +%66 = type { %61 } +%67 = type { %68, %70, %72, %74, %79*, %80 } +%68 = type { %22, %5*, i32, %69 } +%69 = type { %9 } +%70 = type { %71, %67* } +%71 = type { %67* } +%72 = type { %73, %62* } +%73 = type { %64 } +%74 = type { %75, %77* } +%75 = type { %76 } +%76 = type { %77* } +%77 = type { %24, %78, %67* } +%78 = type { %76, %77* } +%79 = type { %34, i32 } +%80 = type { %81* } +%81 = type <{ %9, i32, [4 x i8], %82 }> +%82 = type <{ [33 x i8], [31 x i8] }> +%83 = type <{ [33 x i8], [63 x i8] }> +%84 = type { %85* } +%85 = type { %68, %86, i8 } +%86 = type { %84, %85* } +%87 = type { %88, %67* } +%88 = type { %70 } +%89 = type { %90* } +%90 = type { %68, %91 } +%91 = type { %89, %90* } +%92 = type { %93 } +%93 = type { %94 } +%94 = type { %69*, %69*, %69* } +%95 = type { %96, %99* } +%96 = type { %97 } +%97 = type { %98, %99* } +%98 = type { %99* } +%99 = type <{ %100, %97, %5*, %101 }> +%100 = type { [52 x i8], i32 } +%101 = type <{ [33 x i8], [95 x i8] }> +%102 = type { %16, %41, i32 } + +@_ZL20__gthrw_pthread_oncePiPFvvE = alias weak i32 (i32*, void ()*)* @pthread_once ; [#uses=0] +@_ZL27__gthrw_pthread_getspecificj = alias weak i8* (i32)* @pthread_getspecific ; [#uses=0] +@_ZL27__gthrw_pthread_setspecificjPKv = alias weak i32 (i32, i8*)* @pthread_setspecific ; [#uses=0] +@_ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_ = alias weak i32 (i64*, %0*, i8* (i8*)*, i8*)* @pthread_create ; [#uses=0] +@_ZL22__gthrw_pthread_cancelm = alias weak i32 (i64)* @pthread_cancel ; [#uses=0] +@_ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t = alias weak i32 (%1*)* @pthread_mutex_lock ; [#uses=0] +@_ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t = alias weak i32 (%1*)* @pthread_mutex_trylock ; [#uses=0] +@_ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t = alias weak i32 (%1*)* @pthread_mutex_unlock ; [#uses=0] +@_ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t = alias weak i32 (%1*, %4*)* @pthread_mutex_init ; [#uses=0] +@_ZL26__gthrw_pthread_key_createPjPFvPvE = alias weak i32 (i32*, void (i8*)*)* @pthread_key_create ; [#uses=0] +@_ZL26__gthrw_pthread_key_deletej = alias weak i32 (i32)* @pthread_key_delete ; [#uses=0] +@_ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t = alias weak i32 (%4*)* @pthread_mutexattr_init ; [#uses=0] +@_ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti = alias weak i32 (%4*, i32)* @pthread_mutexattr_settype ; [#uses=0] +@_ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t = alias weak i32 (%4*)* @pthread_mutexattr_destroy ; [#uses=0] + +define fastcc zeroext i8 @_ZN4llvm6Linker11LinkModulesEPNS_6ModuleES2_PSs(%5*, %5*, %69*) nounwind align 2 { + br i1 false, label %4, label %5 + +;