[pkg-d-commits] [ldc] 47/74: Add range metadata when loading bools

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:54:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta2
in repository ldc.

commit c908ebabe419f69e1c093e94d11becce3e8fba05
Author: Martin <noone at nowhere.com>
Date:   Wed May 24 20:36:40 2017 +0200

    Add range metadata when loading bools
    
    When optimizing the code, analogous to clang, fixing one aspect of
    issue #2131.
---
 gen/dvalue.cpp         | 12 ++++++++++++
 tests/codegen/gh2131.d | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/gen/dvalue.cpp b/gen/dvalue.cpp
index 5671adb..5788748 100644
--- a/gen/dvalue.cpp
+++ b/gen/dvalue.cpp
@@ -13,7 +13,9 @@
 #include "gen/llvm.h"
 #include "gen/llvmhelpers.h"
 #include "gen/logger.h"
+#include "gen/optimizer.h"
 #include "gen/tollvm.h"
+#include "llvm/IR/MDBuilder.h"
 
 namespace {
 bool isDefinedInFuncEntryBB(LLValue *v) {
@@ -121,6 +123,16 @@ DRValue *DLValue::getRVal() {
   LLValue *rval = DtoLoad(val);
   if (type->toBasetype()->ty == Tbool) {
     assert(rval->getType() == llvm::Type::getInt8Ty(gIR->context()));
+
+    if (isOptimizationEnabled()) {
+      // attach range metadata for i8 being loaded: [0, 2)
+      llvm::MDBuilder mdBuilder(gIR->context());
+      llvm::cast<llvm::LoadInst>(rval)->setMetadata(
+          llvm::LLVMContext::MD_range,
+          mdBuilder.createRange(llvm::APInt(8, 0), llvm::APInt(8, 2)));
+    }
+
+    // truncate to i1
     rval = gIR->ir->CreateTrunc(rval, llvm::Type::getInt1Ty(gIR->context()));
   }
 
diff --git a/tests/codegen/gh2131.d b/tests/codegen/gh2131.d
new file mode 100644
index 0000000..bd58b79
--- /dev/null
+++ b/tests/codegen/gh2131.d
@@ -0,0 +1,17 @@
+// RUN: %ldc -O3 -enable-cross-module-inlining -output-ll -of=%t.ll %s && FileCheck %s < %t.ll
+
+import core.checkedint;
+
+alias T = size_t;
+
+// CHECK: define {{.*}}@{{.*}}_D6gh21313foo
+T foo(T x, T y, ref bool overflow)
+{
+    // CHECK-NOT: and i8
+    // CHECK: load i8{{.*}}, !range ![[META:[0-9]+]]
+    // CHECK-NOT: and i8
+    // CHECK: ret
+    return mulu(x, y, overflow);
+}
+
+// CHECK: ![[META]] = {{.*}}!{i8 0, i8 2}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list