[llvm] r360431 - [InferAddressSpaces] Enhance the handling of cosntexpr.
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 07:57:42 PDT 2019
Author: hliao
Date: Fri May 10 07:57:42 2019
New Revision: 360431
URL: http://llvm.org/viewvc/llvm-project?rev=360431&view=rev
Log:
[InferAddressSpaces] Enhance the handling of cosntexpr.
Summary:
- Constant expressions may not be added in strict postorder as the
forward instruction scan order. Thus, for a constant express (CE0), if
its operand (CE1) is used in an previous instruction, they are not in
postorder. However, different from
`cloneInstructionWithNewAddressSpace`,
`cloneConstantExprWithNewAddressSpace` doesn't bookkeep uninferred
instructions for later resolving. That results in failure of inferring
constant address.
- This patch adds the support to infer constant expression operand
recursively, since there won't be loop, if that operand is another
constant expression.
Reviewers: arsenm
Subscribers: jholewinski, jvesely, wdng, nhaehnle, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61760
Modified:
llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-getelementptr.ll
llvm/trunk/test/Transforms/InferAddressSpaces/NVPTX/clone_constexpr.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp?rev=360431&r1=360430&r2=360431&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp Fri May 10 07:57:42 2019
@@ -553,10 +553,17 @@ static Value *cloneConstantExprWithNewAd
if (Value *NewOperand = ValueWithNewAddrSpace.lookup(Operand)) {
IsNew = true;
NewOperands.push_back(cast<Constant>(NewOperand));
- } else {
- // Otherwise, reuses the old operand.
- NewOperands.push_back(Operand);
+ continue;
}
+ if (auto CExpr = dyn_cast<ConstantExpr>(Operand))
+ if (Value *NewOperand = cloneConstantExprWithNewAddressSpace(
+ CExpr, NewAddrSpace, ValueWithNewAddrSpace)) {
+ IsNew = true;
+ NewOperands.push_back(cast<Constant>(NewOperand));
+ continue;
+ }
+ // Otherwise, reuses the old operand.
+ NewOperands.push_back(Operand);
}
// If !IsNew, we will replace the Value with itself. However, replaced values
Modified: llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-getelementptr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-getelementptr.ll?rev=360431&r1=360430&r2=360431&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-getelementptr.ll (original)
+++ llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-getelementptr.ll Fri May 10 07:57:42 2019
@@ -71,3 +71,15 @@ define void @repeated_constexpr_gep_addr
ret void
}
+
+; CHECK-LABEL: @unorder_constexpr_gep_bitcast(
+; CHECK-NEXT: %x0 = load i32, i32 addrspace(3)* bitcast ([648 x double] addrspace(3)* @lds to i32 addrspace(3)*), align 4
+; CHECK-NEXT: %x1 = load i32, i32 addrspace(3)* getelementptr (i32, i32 addrspace(3)* bitcast ([648 x double] addrspace(3)* @lds to i32 addrspace(3)*), i32 1), align 4
+define void @unorder_constexpr_gep_bitcast() {
+ %x0 = load i32, i32* bitcast ([648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*) to i32*), align 4
+ %x1 = load i32, i32* getelementptr (i32, i32* bitcast ([648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*) to i32*), i32 1), align 4
+ call void @use(i32 %x0, i32 %x1)
+ ret void
+}
+
+declare void @use(i32, i32)
Modified: llvm/trunk/test/Transforms/InferAddressSpaces/NVPTX/clone_constexpr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferAddressSpaces/NVPTX/clone_constexpr.ll?rev=360431&r1=360430&r2=360431&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InferAddressSpaces/NVPTX/clone_constexpr.ll (original)
+++ llvm/trunk/test/Transforms/InferAddressSpaces/NVPTX/clone_constexpr.ll Fri May 10 07:57:42 2019
@@ -11,7 +11,7 @@ $g1 = comdat any
; CHECK: %idxprom.i = zext i32 %x0 to i64
; CHECK: %arrayidx.i = getelementptr %struct.S, %struct.S* addrspacecast (%struct.S addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 %idxprom.i
; CHECK: tail call void @f1(i32* %arrayidx.i, i32 undef) #0
-; CHECK: %x1 = load i32, i32* getelementptr (%struct.S, %struct.S* addrspacecast (%struct.S addrspace(3)* @g1 to %struct.S*), i64 0, i32 0, i64 0), align 4
+; CHECK: %x1 = load i32, i32 addrspace(3)* getelementptr inbounds (%struct.S, %struct.S addrspace(3)* @g1, i64 0, i32 0, i64 0), align 4
; CHECK: %L.sroa.0.0.insert.ext.i = zext i32 %x1 to i64
; CHECK: tail call void @f2(i64* null, i64 %L.sroa.0.0.insert.ext.i) #0
; CHECK: ret void
More information about the llvm-commits
mailing list