From b393a516fbf09fbe9940adc0ba5aed23f2d25a26 Mon Sep 17 00:00:00 2001 From: Ranjeet Singh Date: Tue, 4 Dec 2018 02:03:53 +0000 Subject: [PATCH] Reverting r348215 Causing failures on ubsan buildbot boxes. llvm-svn: 348230 --- llvm/lib/IR/ConstantFold.cpp | 7 +++--- .../Analysis/ConstantFolding/func-and-folding.ll | 27 ---------------------- .../2004-03-07-FunctionAddressAlignment.ll | 16 +++++++++++++ 3 files changed, 20 insertions(+), 30 deletions(-) delete mode 100644 llvm/test/Analysis/ConstantFolding/func-and-folding.ll create mode 100644 llvm/test/Assembler/2004-03-07-FunctionAddressAlignment.ll diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index d34e383..107975d 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -27,7 +27,6 @@ #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Instructions.h" -#include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/IR/PatternMatch.h" #include "llvm/Support/ErrorHandling.h" @@ -1078,8 +1077,10 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, isa(CE1->getOperand(0))) { GlobalValue *GV = cast(CE1->getOperand(0)); - unsigned GVAlign = - GV->getPointerAlignment(GV->getParent()->getDataLayout()); + // Functions are at least 4-byte aligned. + unsigned GVAlign = GV->getAlignment(); + if (isa(GV)) + GVAlign = std::max(GVAlign, 4U); if (GVAlign > 1) { unsigned DstWidth = CI2->getType()->getBitWidth(); diff --git a/llvm/test/Analysis/ConstantFolding/func-and-folding.ll b/llvm/test/Analysis/ConstantFolding/func-and-folding.ll deleted file mode 100644 index eaa55ab..0000000 --- a/llvm/test/Analysis/ConstantFolding/func-and-folding.ll +++ /dev/null @@ -1,27 +0,0 @@ -; RUN: opt < %s -constprop -S -o - | FileCheck %s - -; Function Attrs: minsize norecurse nounwind optsize readnone -define dso_local void @foo1() #0 { -entry: - ret void -} - -; Function Attrs: minsize norecurse nounwind optsize readnone -define dso_local void @foo2() align 4 { -entry: - ret void -} - -; Function Attrs: minsize nounwind optsize -define dso_local i32 @main() local_unnamed_addr #1 { -entry: -; CHECK: ptrtoint - %call = tail call i32 bitcast (i32 (...)* @process to i32 (i32)*)(i32 and (i32 ptrtoint (void ()* @foo1 to i32), i32 2)) #3 -; CHECK-NEXT: ptrtoint - %call2 = tail call i32 bitcast (i32 (...)* @process to i32 (i32)*)(i32 and (i32 ptrtoint (void ()* @foo2 to i32), i32 2)) #3 - ret i32 0 -} - -; Function Attrs: minsize optsize -declare dso_local i32 @process(...) local_unnamed_addr #2 - diff --git a/llvm/test/Assembler/2004-03-07-FunctionAddressAlignment.ll b/llvm/test/Assembler/2004-03-07-FunctionAddressAlignment.ll new file mode 100644 index 0000000..7fa0802 --- /dev/null +++ b/llvm/test/Assembler/2004-03-07-FunctionAddressAlignment.ll @@ -0,0 +1,16 @@ +; RUN: llvm-as < %s | llvm-dis | not grep ptrtoint +; RUN: verify-uselistorder %s +; All of these should be eliminable + + +define i32 @foo() { + ret i32 and (i32 ptrtoint (i32()* @foo to i32), i32 1) +} + +define i32 @foo2() { + ret i32 and (i32 1, i32 ptrtoint (i32()* @foo2 to i32)) +} + +define i1 @foo3() { + ret i1 icmp ne (i1()* @foo3, i1()* null) +} -- 2.7.4