When we constant fold getelementptr and the indices are vector, the type created is i64 * and not <8 x i64*> which caseuse an assertion to fire in replaceAllUsesWith. I think it's OK just checking for the first index for the reason pointed out in the comment.
Details
Diff Detail
Event Timeline
lib/IR/ConstantFold.cpp | ||
---|---|---|
2063–2070 | Could this be replaced with GetElementPtrInst::getGEPReturnType ? | |
2065 | one or more | |
test/Transforms/InstCombine/gep-vector.ll | ||
2–20 | Can we test the folding more directly? Why do we need the gather call? Couldn't we just have the function ReturnInst contain the GEP ConstantExpr? |
Fixed typo, simplified test.
lib/IR/ConstantFold.cpp | ||
---|---|---|
2063–2070 | hmm, I don't see an overload of getGEPReturnType which takes an ArrayRef of Constant but only Value -- do you want me to add one? |
lib/IR/ConstantFold.cpp | ||
---|---|---|
2063–2070 | I think we can construct an ArrayRef<Value *> from an ArrayRef<Constant *> without violating any safety rules, something like GetElementPtrInst::getGEPReturnType(PtrTy, {Idxs.begin(), Idxs.end()}) or GetElementPtrInst::getGEPReturnType(PtrTy, {Idxs.data(), Idxs.size()}) |
David's comments (also added again the overload which I previously removed because it was unused).
lib/IR/ConstantFold.cpp | ||
---|---|---|
2063–2069 | Do we still need this if/else now that we are using GetElementPtrInst::getGEPReturnType? |
LGTM with the gep instruction replaced with a gep constant expression (all the operands are constant) w/ the test moved to test/Assembler/getelementptr.ll
test/Transforms/InstCombine/gep-vector.ll | ||
---|---|---|
13–16 | I tried to replace this getelemptr with getelementptr inbounds (i64, i64* undef, <8 x i64> undef) but I get a parser error. Is this asimmetry between getelementptr constant expression and getelementptr instruction intended, or am I missing something? |
test/Transforms/InstCombine/gep-vector.ll | ||
---|---|---|
13–16 | Seems to be a bug in LLVM.
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @GV = global i64 0 define <8 x i64*> @patatino2() { %el = getelementptr inbounds i64, i64* @GV, <8 x i64> <i64 0, i64 1, i64 0, i64 1, i64 0, i64 1, i64 0, i64 1> ret <8 x i64*> %el }
It passes the verifier but the parser refuses to deal with it. Worth looking into. |
Isn't this a dead store to GEPTy?