[all-commits] [llvm/llvm-project] b6534b: [Analysis] Don't assume that unsigned overflow can...

Mikhail Maltsev via All-commits all-commits at lists.llvm.org
Thu Oct 17 01:57:52 PDT 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: b6534b2a26fa94e4d09d271faf538b1e4b19ab5d
      https://github.com/llvm/llvm-project/commit/b6534b2a26fa94e4d09d271faf538b1e4b19ab5d
  Author: Mikhail Maltsev <mikhail.maltsev at arm.com>
  Date:   2019-10-17 (Thu, 17 Oct 2019)

  Changed paths:
    M llvm/include/llvm/Analysis/Utils/Local.h
    M llvm/test/Transforms/InstCombine/gep-custom-dl.ll
    M llvm/test/Transforms/InstCombine/getelementptr.ll
    M llvm/test/Transforms/InstCombine/icmp-custom-dl.ll
    M llvm/test/Transforms/InstCombine/icmp.ll
    M llvm/test/Transforms/InstCombine/sub.ll

  Log Message:
  -----------
  [Analysis] Don't assume that unsigned overflow can't happen in EmitGEPOffset (PR42699)

Summary:
Currently when computing a GEP offset using the function EmitGEPOffset
for the following instruction

  getelementptr inbounds i32, i32* %p, i64 %offs

we get

  mul nuw i64 %offs, 4

Unfortunately we cannot assume that unsigned wrapping won't happen
here because %offs is allowed to be negative.

Making such assumptions can lead to miscompilations: see the new test
test24_neg_offs in InstCombine/icmp.ll. Without the patch InstCombine
would generate the following comparison:

   icmp eq i64 %offs, 4611686018427387902; 0x3ffffffffffffffe

Whereas the correct value to compare with is -2.

This patch replaces the NUW flag with NSW in the multiplication
instructions generated by EmitGEPOffset and adjusts the test suite.

https://bugs.llvm.org/show_bug.cgi?id=42699

Reviewers: chandlerc, craig.topper, ostannard, lebedev.ri, spatel, efriedma, nlopes, aqjune

Reviewed By: lebedev.ri

Subscribers: reames, lebedev.ri, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D68342

llvm-svn: 375089




More information about the All-commits mailing list