Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp =================================================================== --- llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -492,6 +492,13 @@ const GEPOperator *GEPOp = dyn_cast(Op); if (!GEPOp) { + if (const auto *PHI = dyn_cast(V)) { + // Look through single-arg phi nodes created by LCSSA. + if (PHI->getNumIncomingValues() == 1) { + V = PHI->getIncomingValue(0); + continue; + } + } if (const auto *Call = dyn_cast(V)) { // CaptureTracking can know about special capturing properties of some // intrinsics like launder.invariant.group, that can't be expressed with @@ -508,19 +515,6 @@ } } - // If it's not a GEP, hand it off to SimplifyInstruction to see if it - // can come up with something. This matches what GetUnderlyingObject does. - if (const Instruction *I = dyn_cast(V)) - // TODO: Get a DominatorTree and AssumptionCache and use them here - // (these are both now available in this function, but this should be - // updated when GetUnderlyingObject is updated). TLI should be - // provided also. - if (const Value *Simplified = - SimplifyInstruction(const_cast(I), DL)) { - V = Simplified; - continue; - } - Decomposed.Base = V; return false; } Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -4150,10 +4150,14 @@ if (GA->isInterposable()) return V; V = GA->getAliasee(); - } else if (isa(V)) { - // An alloca can't be further simplified. - return V; } else { + if (auto *PHI = dyn_cast(V)) { + // Look through single-arg phi nodes created by LCSSA. + if (PHI->getNumIncomingValues() == 1) { + V = PHI->getIncomingValue(0); + continue; + } + } if (auto *Call = dyn_cast(V)) { // CaptureTracking can know about special capturing properties of some // intrinsics like launder.invariant.group, that can't be expressed with @@ -4170,14 +4174,6 @@ } } - // See if InstructionSimplify knows any relevant tricks. - if (Instruction *I = dyn_cast(V)) - // TODO: Acquire a DominatorTree and AssumptionCache and use them. - if (Value *Simplified = SimplifyInstruction(I, {DL, I})) { - V = Simplified; - continue; - } - return V; } assert(V->getType()->isPointerTy() && "Unexpected operand type!"); Index: llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-select.ll =================================================================== --- llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-select.ll +++ llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-select.ll @@ -61,21 +61,18 @@ ret void } +; FIXME: Can be promoted, but we'd have to recursively show that the select +; operands all point to the same alloca. + ; CHECK-LABEL: @lds_promoted_alloca_select_input_select( -; CHECK: getelementptr inbounds [256 x [16 x i32]], [256 x [16 x i32]] addrspace(3)* @lds_promoted_alloca_select_input_select.alloca, i32 0, i32 %{{[0-9]+}} -; CHECK: %ptr0 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(3)* %{{[0-9]+}}, i32 0, i32 %a -; CHECK: %ptr1 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(3)* %{{[0-9]+}}, i32 0, i32 %b -; CHECK: %ptr2 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(3)* %{{[0-9]+}}, i32 0, i32 %c -; CHECK: %select0 = select i1 undef, i32 addrspace(3)* %ptr0, i32 addrspace(3)* %ptr1 -; CHECK: %select1 = select i1 undef, i32 addrspace(3)* %select0, i32 addrspace(3)* %ptr2 -; CHECK: store i32 0, i32 addrspace(3)* %select1, align 4 -define amdgpu_kernel void @lds_promoted_alloca_select_input_select(i32 %a, i32 %b, i32 %c) #0 { +; CHECK: alloca +define amdgpu_kernel void @lds_promoted_alloca_select_input_select(i32 %a, i32 %b, i32 %c, i1 %c1, i1 %c2) #0 { %alloca = alloca [16 x i32], align 4, addrspace(5) %ptr0 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 %a %ptr1 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 %b %ptr2 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 %c - %select0 = select i1 undef, i32 addrspace(5)* %ptr0, i32 addrspace(5)* %ptr1 - %select1 = select i1 undef, i32 addrspace(5)* %select0, i32 addrspace(5)* %ptr2 + %select0 = select i1 %c1, i32 addrspace(5)* %ptr0, i32 addrspace(5)* %ptr1 + %select1 = select i1 %c2, i32 addrspace(5)* %select0, i32 addrspace(5)* %ptr2 store i32 0, i32 addrspace(5)* %select1, align 4 ret void }