[llvm] r275532 - [IR] andIRFlags and copyIRFlags needs to handle GEP
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 22:02:31 PDT 2016
Author: majnemer
Date: Fri Jul 15 00:02:31 2016
New Revision: 275532
URL: http://llvm.org/viewvc/llvm-project?rev=275532&view=rev
Log:
[IR] andIRFlags and copyIRFlags needs to handle GEP
We didn't consider the inbounds flag on GEPs leading to downstream users
introducing UB.
This fixes PR28562.
Added:
llvm/trunk/test/Transforms/GVN/pr28562.ll
Modified:
llvm/trunk/lib/IR/Instruction.cpp
Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=275532&r1=275531&r2=275532&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Fri Jul 15 00:02:31 2016
@@ -232,6 +232,10 @@ void Instruction::copyIRFlags(const Valu
if (auto *FP = dyn_cast<FPMathOperator>(V))
if (isa<FPMathOperator>(this))
copyFastMathFlags(FP->getFastMathFlags());
+
+ if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
+ if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
+ DestGEP->setIsInBounds(SrcGEP->isInBounds() | DestGEP->isInBounds());
}
void Instruction::andIRFlags(const Value *V) {
@@ -253,6 +257,10 @@ void Instruction::andIRFlags(const Value
copyFastMathFlags(FM);
}
}
+
+ if (auto *SrcGEP = dyn_cast<GetElementPtrInst>(V))
+ if (auto *DestGEP = dyn_cast<GetElementPtrInst>(this))
+ DestGEP->setIsInBounds(SrcGEP->isInBounds() & DestGEP->isInBounds());
}
const char *Instruction::getOpcodeName(unsigned OpCode) {
Added: llvm/trunk/test/Transforms/GVN/pr28562.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/pr28562.ll?rev=275532&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/pr28562.ll (added)
+++ llvm/trunk/test/Transforms/GVN/pr28562.ll Fri Jul 15 00:02:31 2016
@@ -0,0 +1,9 @@
+; RUN: opt -S -gvn < %s | FileCheck %s
+define i32* @test1(i32* %a) {
+ %x1 = getelementptr inbounds i32, i32* %a, i32 10
+ %x2 = getelementptr i32, i32* %a, i32 10
+ ret i32* %x2
+; CHECK-LABEL: @test1(
+; CHECK: %[[x:.*]] = getelementptr i32, i32* %a, i32 10
+; CHECK: ret i32* %[[x]]
+}
More information about the llvm-commits
mailing list